/*****************************************************************************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 the sphere visual class.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: 28 Sep 199539*40* Modification history:41*42* 28 Sep 1995, modified vis_initialize_sphere_visual to set the VisualName43* field of the visual_type structure44*45* 29 Sep 1995, modified vis_initialize_sphere_visual to set new field46* VisualParams of the visual_type structure, and removed47* vis_spehre_set_param routine, the program now uses the48* visual_params_t structure and the routine vis_set_param49* in file visual.c50*51* Juha R.52*53******************************************************************************/5455#include "../elmerpost.h"56/******************************************************************************57*58* Parameter structure definitions for sphere visual class59*60******************************************************************************/61typedef struct shpere_s62{63scalar_t *ColorData;64scalar_t *RadiusData;6566double RadiusScale;6768scalar_t *ThresholdData;69double Floor,Ceiling;7071material_t *Material;72colormap_t *ColorMap;7374int Quality;75} sphere_t;7677/*******************************************************************************78*79* Name: vis_sphere80*81* Purpose: draw sphere as lines or surface, with color coded or not82*83* Parameters:84*85* Input: (geometry_t *) geometry description86* (sphere_t *) sphere display parameters87* (double)88*89* Output: graphics90*91* Return value: if mouse interaction is going on, and time used exceeds92* given value (TooLong1,2) FALSE, otherwise TRUE93*94******************************************************************************/95static int vis_sphere( geometry_t *geometry, element_model_t *model, sphere_t *Sphere,double dt )96{97scalar_t *RadiusData = Sphere->RadiusData;98scalar_t *ColorData = Sphere->ColorData;99scalar_t *ThresholdData = Sphere->ThresholdData;100101vertex_t *v = geometry->Vertices;102103vertex_face_t *face;104105int i,j,quick,N=geometry->VertexCount;106107double *C=NULL, *R=NULL, *T=NULL;108double CScl=1.0,CAdd=0.0,RScl=1.0,RAdd=0.0,Rad=1.0,Col=1.0;109110void gra_set_colormap(), gra_sphere_quality(), gra_set_material(), gra_point(), gra_sphere();111112if ( !GlobalOptions.StereoMode )113if ( Sphere->Material->Diffuse[3] < 1.0 )114{115if ( GlobalPass != 0 ) return TRUE;116} else if ( GlobalPass == 0 )117{118return TRUE;119}120121if ( ColorData && ColorData->f )122{123C = ColorData->f;124CAdd = ColorData->min;125CScl = 1.0/(ColorData->max - ColorData->min);126127gra_set_colormap( Sphere->ColorMap );128} else gra_set_colormap( NULL );129130if ( RadiusData && RadiusData->f )131{132R = RadiusData->f;133RAdd = RadiusData->min;134RScl = 1.0/(RadiusData->max - RadiusData->min);135}136else { RAdd = 0.0; RScl = 0.05*Sphere->RadiusScale; }137138if ( ThresholdData && ThresholdData->f ) T = ThresholdData->f;139140quick = (epMouseDown && epMouseDownTakesTooLong) || (Sphere->Quality < 0);141142if ( quick )143{144gra_begin( GRA_POINTS );145#if 0146gra_polygon_mode( GRA_LINE );147gra_sphere_quality( 1 );148#endif149} else {150gra_sphere_quality( Sphere->Quality );151if ( Sphere->Quality == 0 ) gra_polygon_mode( GRA_LINE );152}153154gra_set_material( Sphere->Material );155156for( i=0; i<N; i++ )157{158if ( v[i].ElementModelNode )159{160for( face=v[i].Faces; face!=NULL; face=face->Next )161{162if ( geometry->Triangles[face->Face].Element->DisplayFlag ) break;163}164#if 1165if ( v[i].Faces && !face ) continue;166#else167if ( !face ) continue;168#endif169170if ( T && (T[i]<Sphere->Floor || T[i]>Sphere->Ceiling) ) continue;171172if ( R )173Rad = RScl*(R[i]-RAdd)+0.05;174else Rad = 1.0;175176Rad *= 0.05*Sphere->RadiusScale;177178if ( C ) Col = CScl*(C[i] - CAdd); else Col = CScl;179180if ( quick ) {181gra_point( v[i].x[0],v[i].x[1],v[i].x[2],Col,Rad );182} else {183gra_sphere( v[i].x[0],v[i].x[1],v[i].x[2],Col,Rad );184}185186} else break;187188if ( epMouseDown && (i & 8) )189{190if ( !epMouseDownTakesTooLong )191{192if ( RealTime() - dt > TooLong1 )193{194if ( quick ) gra_end();195gra_polygon_mode( GRA_FILL );196++epMouseDownTakesTooLong;197return FALSE;198}199}200else if ( RealTime() - dt > TooLong2 )201if ( ++epMouseDownTakesTooLong > 3 )202{203gra_end();204gra_polygon_mode( GRA_FILL );205return FALSE;206} else dt = RealTime();207}208209if ( BreakLoop ) break;210}211212if ( quick ) gra_end();213gra_polygon_mode( GRA_FILL );214215return TRUE;216}217218219/*******************************************************************************220*221* Name: vis_sphere_alloc222*223* Purpose: allocate memory for sphere_t structure224*225* Parameters:226*227* Input: none228*229* Output: none230*231* Return value: pointer to allocated memory232*233******************************************************************************/234static sphere_t *vis_sphere_alloc()235{236sphere_t *sphere = (sphere_t *)calloc(sizeof(sphere_t),1);237238if ( !sphere )239{240fprintf( stderr, "vis_sphere_alloc: FATAL: can't alloc a few bytes of memory\n" );241}242243return sphere;244}245246/*******************************************************************************247*248* Name: vis_sphere_delete249*250* Purpose: free memory associated with sphere_t structure251*252* Parameters:253*254* Input: (sphere_t *) pointer to structure255*256* Output: none257*258* Return value: void259*260******************************************************************************/261static void vis_sphere_delete(sphere_t *sphere)262{263if ( sphere ) free( sphere );264}265266/*******************************************************************************267*268* Name: vis_initialize_sphere_visual269*270* Purpose: Register "Spheres" visual type271*272* Parameters:273*274* Input: none275*276* Output: none277*278* Return value: vis_add_visual_type (malloc success probably)...279*280******************************************************************************/281int vis_initialize_sphere_visual()282{283static char *visual_name = "Spheres";284visual_type_t VisualDef;285286static sphere_t sphere;287288int n = 0;289290static visual_param_t SphereParams[] =291{292{ "ColorData", "%s", 0, VIS_VISUAL_PARAM_POINTER, 0, 0.0, NULL },293{ "RadiusData", "%s", 0, VIS_VISUAL_PARAM_POINTER, 0, 0.0, NULL },294{ "RadiusScale", "%lf", 0, VIS_VISUAL_PARAM_FLOAT, 0, 1.0, NULL },295{ "ThresholdData", "%s", 0, VIS_VISUAL_PARAM_POINTER, 0, 1.0, NULL },296{ "Floor", "%lf", 0, VIS_VISUAL_PARAM_FLOAT, 0, 0.0, NULL },297{ "Ceiling", "%lf", 0, VIS_VISUAL_PARAM_FLOAT, 0, 1.0, NULL },298{ "Material", "%s", 0, VIS_VISUAL_PARAM_POINTER, 0, 0.0, &DefaultMaterial },299{ "ColorMap", "%s", 0, VIS_VISUAL_PARAM_POINTER, 0, 0.0, &DefaultColorMap },300{ "Quality", "%d", 0, VIS_VISUAL_PARAM_INT, 1, 0.0, NULL },301{ NULL, NULL, 0, 0, 0, 0.0, NULL }302};303304SphereParams[n++].Offset = (char *)&sphere.ColorData - (char *)&sphere;305SphereParams[n++].Offset = (char *)&sphere.RadiusData - (char *)&sphere;306SphereParams[n++].Offset = (char *)&sphere.RadiusScale - (char *)&sphere;307SphereParams[n++].Offset = (char *)&sphere.ThresholdData - (char *)&sphere;308SphereParams[n++].Offset = (char *)&sphere.Floor - (char *)&sphere;309SphereParams[n++].Offset = (char *)&sphere.Ceiling - (char *)&sphere;310SphereParams[n++].Offset = (char *)&sphere.Material - (char *)&sphere;311SphereParams[n++].Offset = (char *)&sphere.ColorMap - (char *)&sphere;312SphereParams[n++].Offset = (char *)&sphere.Quality - (char *)&sphere;313314VisualDef.VisualName = visual_name;315VisualDef.RealizeVisual = (int (*)()) vis_sphere;316VisualDef.AllocParams = (void *(*)()) vis_sphere_alloc;317VisualDef.DeleteParams = (void (*)()) vis_sphere_delete;318VisualDef.VisualParams = SphereParams;319320return vis_add_visual_type( &VisualDef );321}322323324