/*****************************************************************************1*2* Elmer, A Finite Element Software for Multiphysical Problems3*4* Copyright 1st April 1995 - , CSC - IT Center for Science Ltd., Finland5*6* This program is free software; you can redistribute it and/or7* modify it under the terms of the GNU General Public License8* as published by the Free Software Foundation; either version 29* of the License, or (at your option) any later version.10*11* This program is distributed in the hope that it will be useful,12* but WITHOUT ANY WARRANTY; without even the implied warranty of13* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the14* GNU General Public License for more details.15*16* You should have received a copy of the GNU General Public License17* along with this program (in file fem/GPL-2); if not, write to the18* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,19* Boston, MA 02110-1301, USA.20*21*****************************************************************************/2223/*******************************************************************************24*25* Action routines for visual class ContourLines.26*27*******************************************************************************28*29* Author: Juha Ruokolainen30*31* Address: CSC - IT Center for Science Ltd.32* Keilaranta 14, P.O. BOX 40533* 02101 Espoo, Finland34* Tel. +358 0 457 272335* Telefax: +358 0 457 230236* EMail: [email protected]37*38* Date: 26 Sep 199539*40*41* Modification history:42*43* 28 Sep 1995, modified vis_initialize_contour_lines_visual to set the44* VisualName field of the visual_type structure45*46* Juha R.47*48******************************************************************************/4950#include "../elmerpost.h"5152/******************************************************************************53*54* Parameter structure definitions for Contour Lines visual class55*56******************************************************************************/5758typedef struct contour_lines_s59{60scalar_t *ContourData;61scalar_t *ColorData;6263int NofLevels;64double *Levels;6566material_t *Material;67colormap_t *ColorMap;6869int LineQuality;70double LineWidth;7172line_style_t LineStyle;73} contour_lines_t;7475/*******************************************************************************76*77* Name: vis_get_isolines78*79* Purpose: Extract isolines with given threshold80*81* Parameters:82*83* Input: (triangle_t *)84* (vertex_t *)85* (double *,double,double) color quantity, and scales => 0,186* (double *) surface quantity87* (double) threshold value88*89* Output: (line_t *) place to store the line90*91* Return value: number of points generated, line exists if (n>=2)92*93******************************************************************************/94static int vis_get_isolines95(96element_model_t *model, element_t *element, vertex_t *vertices, line_t *Lines,97double *C, double *F, int nlevels, double *levels,double CScl,double CAdd98)99{100static double x[ELM_MAX_ELEMENT_NODES];101static double y[ELM_MAX_ELEMENT_NODES];102static double z[ELM_MAX_ELEMENT_NODES];103static double f[ELM_MAX_ELEMENT_NODES];104static double c[ELM_MAX_ELEMENT_NODES];105106int i,j,n,*T=element->Topology;107element_type_t *elmt = element->ElementType;108109if ( elmt->IsoLine )110{111for( i=0; i<elmt->NumberOfNodes; i++ )112{113x[i] = vertices[T[i]].x[0];114y[i] = vertices[T[i]].x[1];115z[i] = vertices[T[i]].x[2];116117f[i] = F[T[i]];118119if ( C )120c[i] = CScl*(C[T[i]]-CAdd);121else122c[i] = 0.0;123}124125n = 0;126for( i=0; i<nlevels; i++ )127{128n += (*elmt->IsoLine)( levels[i],f,c,x,y,z,&Lines[n] );129}130131return n;132}133134return 0;135}136137138/*******************************************************************************139*140* Name: vis_draw_line141*142* Purpose: Draw a line143*144* Parameters:145*146* Input: (line_t *)147* (int ) line/solid148* (double) width of line149*150* Output: graphics151*152* Return value: void153*154******************************************************************************/155static void vis_draw_line( line_t *line, int quick, double width )156{157float x[2][3],c0,c1;158void gra_line(), gra_sphere();159160x[0][0] = line->x[0];161x[0][1] = line->y[0];162x[0][2] = line->z[0];163164x[1][0] = line->x[1];165x[1][1] = line->y[1];166x[1][2] = line->z[1];167168c0 = line->c[0];169c1 = line->c[1];170171if ( quick )172{173gra_line( x[0],c0,x[1],c1,line_style_line,width );174} else175{176gra_line( x[0],c0,x[1],c1,line_style_cylinder,width );177gra_sphere( x[0][0],x[0][1],x[0][2],c0, width );178gra_sphere( x[1][0],x[1][1],x[1][2],c1, width );179}180}181182/*******************************************************************************183*184* Name: vis_contour_lines185*186* Purpose: Draw contour lines given data, and threshold values187*188* Parameters:189*190* Input: (geometry_t *)191* (contour_lines_t *) contour line display params192* (double) time used193*194* Output: graphics195*196* Return value: if mouse interaction is going on, and time used exceeds197* given value (TooLong1,2) FALSE, otherwise TRUE198*199******************************************************************************/200static int vis_contour_lines( geometry_t *geometry, element_model_t *model, contour_lines_t *ContourLines,double dt )201{202double CScl,CAdd,*Levels=ContourLines->Levels;203double *C=NULL, *F=NULL;204205scalar_t *ColorData = ContourLines->ColorData;206scalar_t *ContourData = ContourLines->ContourData;207208int i,j,n,quick;209210double width = ContourLines->LineWidth*0.005;211212static line_t Lines[1000];213214element_t *elements = model->Elements;215216void gra_set_colormap(), gra_sphere_quality(), gra_set_material();217218if ( !ContourData || !ContourData->f ) return TRUE;219220if ( !GlobalOptions.StereoMode )221if ( ContourLines->Material->Diffuse[3] < 1.0 )222{223if ( GlobalPass != 0 ) return TRUE;224} else if ( GlobalPass == 0 )225{226return TRUE;227}228229F = ContourData->f;230231if ( ColorData && ColorData->f )232{233CAdd = ColorData->min;234CScl = 1.0/(ColorData->max - ColorData->min);235236C = ColorData->f;237238gra_set_colormap( ContourLines->ColorMap );239} else gra_set_colormap( NULL );240241quick = ContourLines->LineStyle == line_style_line;242quick |= epMouseDown && epMouseDownTakesTooLong;243244if ( !quick && (ContourLines->LineStyle == line_style_cylinder) )245{246gra_sphere_quality( ContourLines->LineQuality );247}248249if ( quick && !(epMouseDown && epMouseDownTakesTooLong) )250{251gra_line_width( ContourLines->LineWidth );252} else {253gra_line_width( 1.0 );254}255256gra_set_material( ContourLines->Material );257258if ( quick ) gra_beg_lines();259260for( i=0; i<model->NofElements; i++ )261{262263if ( !elements[i].DisplayFlag ) continue;264265n = vis_get_isolines266(267model,&elements[i],geometry->Vertices,Lines,C,F,ContourLines->NofLevels,Levels,CScl,CAdd268);269for( j=0; j<n; j++ ) vis_draw_line( &Lines[j], quick, width );270271if ( epMouseDown )272{273if ( quick )274{275if ( (i & 32) && (RealTime() - dt > TooLong2) )276if ( ++epMouseDownTakesTooLong > 3 )277{278gra_end_lines();279return FALSE;280} else dt = RealTime();281} else282{283if ( RealTime() - dt > TooLong1 )284{285epMouseDownTakesTooLong++;286return FALSE;287}288}289}290291if ( BreakLoop ) break;292}293294if ( quick ) gra_end_lines();295296return TRUE;297}298299300/*******************************************************************************301*302* Name: vis_contour_lines_alloc303*304* Purpose: allocate memory for contour_lines_t structure305*306* Parameters:307*308* Input: none309*310* Output: none311*312* Return value: pointer to allocated memory313*314******************************************************************************/315static contour_lines_t *vis_contour_lines_alloc()316{317contour_lines_t *contour_line = (contour_lines_t *)calloc(sizeof(contour_lines_t),1);318319if ( !contour_line )320{321fprintf( stderr, "vis_contour_lines_alloc: FATAL: can't alloc a few bytes of memory\n" );322}323324return contour_line;325}326327/*******************************************************************************328*329* Name: vis_contour_lines_delete330*331* Purpose: free memory associated with contour_lines_t structure332*333* Parameters:334*335* Input: (contour_lines_t *) pointer to structure336*337* Output: none338*339* Return value: void340*341******************************************************************************/342static void vis_contour_lines_delete(contour_lines_t *contour_line)343{344if ( contour_line ) free( contour_line );345}346347/*******************************************************************************348*349* Name: vis_initialize_contour_lines_visual350*351* Purpose: Register "Contour Line" visual type352*353* Parameters:354*355* Input: none356*357* Output: none358*359* Return value: vis_add_visual_type (malloc success probably)...360*361******************************************************************************/362int vis_initialize_contour_line_visual()363{364static char *visual_name = "Contour Lines";365visual_type_t VisualDef;366367static contour_lines_t contours;368369static visual_param_t ContourLineParams[] =370{371{ "ContourData", "%s", 0, VIS_VISUAL_PARAM_POINTER, 0, 0.0, NULL },372{ "ColorData", "%s", 0, VIS_VISUAL_PARAM_POINTER, 0, 0.0, NULL },373{ "NofLevels","%d", 0, VIS_VISUAL_PARAM_INT, 0, 0.0, NULL },374{ "Levels", "%s", 0, VIS_VISUAL_PARAM_POINTER, 0, 0.0, NULL },375{ "Material", "%s", 0, VIS_VISUAL_PARAM_POINTER, 0, 0.0, &DefaultMaterial },376{ "ColorMap", "%s", 0, VIS_VISUAL_PARAM_POINTER, 0, 0.0, &DefaultColorMap },377{ "LineWidth", "%lf", 0, VIS_VISUAL_PARAM_FLOAT, 0, 1.0, NULL },378{ "LineQuality", "%d", 0, VIS_VISUAL_PARAM_INT, 1, 0.0, NULL },379{ "LineStyle", "%d", 0, VIS_VISUAL_PARAM_INT,line_style_line, 0.0, NULL },380{ NULL, NULL, 0, 0, 0, 0.0, NULL }381};382383int n = 0;384385ContourLineParams[n++].Offset = (char *)&contours.ContourData - (char *)&contours;386ContourLineParams[n++].Offset = (char *)&contours.ColorData - (char *)&contours;387ContourLineParams[n++].Offset = (char *)&contours.NofLevels - (char *)&contours;388ContourLineParams[n++].Offset = (char *)&contours.Levels - (char *)&contours;389ContourLineParams[n++].Offset = (char *)&contours.Material - (char *)&contours;390ContourLineParams[n++].Offset = (char *)&contours.ColorMap - (char *)&contours;391ContourLineParams[n++].Offset = (char *)&contours.LineWidth - (char *)&contours;392ContourLineParams[n++].Offset = (char *)&contours.LineQuality - (char *)&contours;393ContourLineParams[n++].Offset = (char *)&contours.LineStyle - (char *)&contours;394395VisualDef.VisualName = visual_name;396397VisualDef.RealizeVisual = (int (*)()) vis_contour_lines;398VisualDef.AllocParams = (void *(*)()) vis_contour_lines_alloc;399VisualDef.DeleteParams = (void (*)()) vis_contour_lines_delete;400VisualDef.VisualParams = ContourLineParams;401402return vis_add_visual_type( &VisualDef );403}404405406