[cig-commits] commit: Add EquationShape
Mercurial
hg at geodynamics.org
Wed Nov 9 00:55:10 PST 2011
changeset: 634:56dbfba1e984
tag: tip
user: Walter Landry <wlandry at caltech.edu>
date: Wed Nov 09 00:54:58 2011 -0800
files: Shape/src/EquationShape.cxx Shape/src/EquationShape.cxx~ Shape/src/EquationShape.h Shape/src/EquationShape.meta Shape/src/Init.cxx Shape/src/Shape.h Shape/src/types.h
description:
Add EquationShape
diff -r ae3bb598eb97 -r 56dbfba1e984 Shape/src/EquationShape.cxx
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Shape/src/EquationShape.cxx Wed Nov 09 00:54:58 2011 -0800
@@ -0,0 +1,209 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+** Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+** Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+** Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+** Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org) )
+** Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+** Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+** This library is free software; you can redistribute it and/or
+** modify it under the terms of the GNU Lesser General Public
+** License as published by the Free Software Foundation; either
+** version 2.1 of the License, or (at your option) any later version.
+**
+** This library is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+** Lesser General Public License for more details.
+**
+** You should have received a copy of the GNU Lesser General Public
+** License along with this library; if not, write to the Free Software
+** Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+**
+** $Id: EquationShape.c 4056 2007-03-29 04:55:51Z JulianGiordani $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/Geometry/Geometry.h>
+#include <StgDomain/Shape/Shape.h>
+#include <StgDomain/Mesh/Mesh.h>
+#include <StgDomain/Utils/Utils.h>
+
+#include "types.h"
+#include "ShapeClass.h"
+#include "EquationShape.h"
+
+
+#include <assert.h>
+#include <string.h>
+#include <math.h>
+
+/* Textual name of this class */
+const Type EquationShape_Type = "EquationShape";
+
+/*----------------------------------------------------------------------------------------------------------------------------------
+** Constructors
+*/
+
+EquationShape* EquationShape_New(Name name,
+ Dimension_Index dim,
+ XYZ centre,
+ double alpha,
+ double beta,
+ double gamma,
+ char* equation)
+{
+ EquationShape* self = (EquationShape*)_EquationShape_DefaultNew( name );
+
+ _Stg_Shape_Init( self, dim, centre, False, alpha, beta, gamma);
+ _EquationShape_Init( self, equation );
+ return self;
+}
+
+EquationShape* _EquationShape_New( EQUATIONSHAPE_DEFARGS )
+{
+ EquationShape* self;
+
+ /* Allocate memory */
+ assert( _sizeOfSelf >= sizeof(EquationShape) );
+ self = (EquationShape*)_Stg_Shape_New( STG_SHAPE_PASSARGS );
+
+ /* General info */
+ return self;
+}
+
+void _EquationShape_Init( void* equation, char *eqn ) {
+ EquationShape* self = (EquationShape*)equation;
+
+ self->equation = StG_Strdup(eqn);
+}
+
+/*------------------------------------------------------------------------------------------------------------------------
+** Virtual functions
+*/
+
+void _EquationShape_Delete( void* equation ) {
+ EquationShape* self = (EquationShape*)equation;
+
+ /* Delete parent */
+ _Stg_Shape_Delete( self );
+}
+
+
+void _EquationShape_Print( void* equation, Stream* stream ) {
+ EquationShape* self = (EquationShape*)equation;
+
+ /* Print parent */
+ _Stg_Shape_Print( self, stream );
+}
+
+
+
+void* _EquationShape_Copy( const void* equation, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
+ EquationShape* self = (EquationShape*)equation;
+ EquationShape* newEquationShape;
+
+ newEquationShape = (EquationShape*)_Stg_Shape_Copy( self, dest, deep, nameExt, ptrMap );
+
+ newEquationShape->equation = StG_Strdup(self->equation);
+ return (void*)newEquationShape;
+}
+
+void* _EquationShape_DefaultNew( Name name ) {
+ /* Variables set in this function */
+ SizeT _sizeOfSelf = sizeof(EquationShape);
+ Type type = EquationShape_Type;
+ Stg_Class_DeleteFunction* _delete = _EquationShape_Delete;
+ Stg_Class_PrintFunction* _print = _EquationShape_Print;
+ Stg_Class_CopyFunction* _copy = _EquationShape_Copy;
+ Stg_Component_DefaultConstructorFunction* _defaultConstructor = _EquationShape_DefaultNew;
+ Stg_Component_ConstructFunction* _construct = _EquationShape_AssignFromXML;
+ Stg_Component_BuildFunction* _build = _EquationShape_Build;
+ Stg_Component_InitialiseFunction* _initialise = _EquationShape_Initialise;
+ Stg_Component_ExecuteFunction* _execute = _EquationShape_Execute;
+ Stg_Component_DestroyFunction* _destroy = _EquationShape_Destroy;
+ Stg_Shape_IsCoordInsideFunction* _isCoordInside = _EquationShape_IsCoordInside;
+ Stg_Shape_CalculateVolumeFunction* _calculateVolume = _EquationShape_CalculateVolume;
+ Stg_Shape_DistanceFromCenterAxisFunction* _distanceFromCenterAxis = _EquationShape_DistanceFromCenterAxis;
+
+ /* Variables that are set to ZERO are variables that will be set either by the current _New function or another parent _New function further up the hierachy */
+ AllocationType nameAllocationType = NON_GLOBAL /* default value NON_GLOBAL */;
+
+ return (void*) _EquationShape_New( EQUATIONSHAPE_PASSARGS );
+}
+
+
+void _EquationShape_AssignFromXML( void* equation, Stg_ComponentFactory* cf, void* data ) {
+ EquationShape* self = (EquationShape*)equation;
+
+ _Stg_Shape_AssignFromXML( self, cf, data );
+
+ char *eqn = Stg_ComponentFactory_GetString( cf, self->name, (Dictionary_Entry_Key)"equation", "");
+ _EquationShape_Init( self, eqn );
+}
+
+void _EquationShape_Build( void* equation, void* data ) {
+ EquationShape* self = (EquationShape*)equation;
+
+ _Stg_Shape_Build( self, data );
+}
+
+void _EquationShape_Initialise( void* equation, void* data ) {
+ EquationShape* self = (EquationShape*)equation;
+
+ _Stg_Shape_Initialise( self, data );
+}
+
+void _EquationShape_Execute( void* equation, void* data ) {
+ EquationShape* self = (EquationShape*)equation;
+
+ _Stg_Shape_Execute( self, data );
+}
+
+void _EquationShape_Destroy( void* equation, void* data ) {
+ EquationShape* self = (EquationShape*)equation;
+
+ Memory_Free(self->equation);
+ _Stg_Shape_Destroy( self, data );
+}
+
+/*--------------------------------------------------------------------------------------------------------------------------
+** Public Functions
+*/
+
+/*---------------------------------------------------------------------------------------------------------------------
+** Private Member functions
+*/
+
+Bool _EquationShape_IsCoordInside( void* equation, const Coord coord ) {
+ EquationShape* self=(EquationShape*) equation;
+ Coord newCoord;
+
+ /* Transform coordinate into canonical reference frame */
+ Stg_Shape_TransformCoord( self, coord, newCoord );
+
+ return Equation_eval(newCoord,(DomainContext*)(self->context),
+ self->equation)>=0 ? True : False;
+}
+
+
+double _EquationShape_CalculateVolume( void* equation ) {
+ assert( 0 );
+ return 0.0;
+}
+
+void _EquationShape_DistanceFromCenterAxis( void* shape, const Coord coord, double* disVec ){
+ Stg_Shape* self = (Stg_Shape*)shape;
+ Journal_Firewall( False, Journal_Register( Error_Type, (Name)self->type ),
+ "Error in function %s: This functions hasn't been implemented.",
+ "Please inform cig-long at geodynamics.org that you have received this error.\n", __func__ );
+}
+
+
+
diff -r ae3bb598eb97 -r 56dbfba1e984 Shape/src/EquationShape.cxx~
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Shape/src/EquationShape.cxx~ Wed Nov 09 00:54:58 2011 -0800
@@ -0,0 +1,337 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+** Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+** Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+** Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+** Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org) )
+** Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+** Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+** This library is free software; you can redistribute it and/or
+** modify it under the terms of the GNU Lesser General Public
+** License as published by the Free Software Foundation; either
+** version 2.1 of the License, or (at your option) any later version.
+**
+** This library is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+** Lesser General Public License for more details.
+**
+** You should have received a copy of the GNU Lesser General Public
+** License along with this library; if not, write to the Free Software
+** Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+**
+** $Id: EquationShape.c 4056 2007-03-29 04:55:51Z JulianGiordani $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/Geometry/Geometry.h>
+
+#include "types.h"
+#include "ShapeClass.h"
+#include "EquationShape.h"
+
+#include <assert.h>
+#include <string.h>
+#include <math.h>
+
+/* Textual name of this class */
+const Type EquationShape_Type = "EquationShape";
+
+/*----------------------------------------------------------------------------------------------------------------------------------
+** Constructors
+*/
+
+EquationShape* EquationShape_New(
+ Name name,
+ Dimension_Index dim,
+ XYZ centre,
+ double alpha,
+ double beta,
+ double gamma,
+ Coord_List vertexList,
+ Index vertexCount,
+ XYZ start,
+ XYZ end,
+ Axis perpendicularAxis )
+{
+ EquationShape* self = (EquationShape*)_EquationShape_DefaultNew( name );
+
+ _Stg_Shape_Init( self, dim, centre, False, alpha, beta, gamma);
+ _EquationShape_Init( self, vertexList, vertexCount, start, end, perpendicularAxis );
+ return self;
+}
+
+EquationShape* _EquationShape_New( POLYGONSHAPE_DEFARGS )
+{
+ EquationShape* self;
+
+ /* Allocate memory */
+ assert( _sizeOfSelf >= sizeof(EquationShape) );
+ self = (EquationShape*)_Stg_Shape_New( STG_SHAPE_PASSARGS );
+
+ /* General info */
+ return self;
+}
+
+void _EquationShape_Init( void* polygon, Coord_List vertexList, Index vertexCount, XYZ start, XYZ end, Axis perpendicularAxis ) {
+ EquationShape* self = (EquationShape*)polygon;
+
+ self->vertexList = Memory_Alloc_Array( Coord, vertexCount, "vertexList" );
+ memcpy( self->vertexList , vertexList, sizeof(Coord) * vertexCount );
+ self->vertexCount = vertexCount;
+ memcpy( self->start , start, sizeof(XYZ) );
+ memcpy( self->end , end, sizeof(XYZ) );
+ self->perpendicularAxis = perpendicularAxis;
+}
+
+/*------------------------------------------------------------------------------------------------------------------------
+** Virtual functions
+*/
+
+void _EquationShape_Delete( void* polygon ) {
+ EquationShape* self = (EquationShape*)polygon;
+
+ /* Delete parent */
+ _Stg_Shape_Delete( self );
+}
+
+
+void _EquationShape_Print( void* polygon, Stream* stream ) {
+ EquationShape* self = (EquationShape*)polygon;
+
+ /* Print parent */
+ _Stg_Shape_Print( self, stream );
+}
+
+
+
+void* _EquationShape_Copy( const void* polygon, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
+ EquationShape* self = (EquationShape*)polygon;
+ EquationShape* newEquationShape;
+
+ newEquationShape = (EquationShape*)_Stg_Shape_Copy( self, dest, deep, nameExt, ptrMap );
+
+ newEquationShape->vertexList = Memory_Alloc_Array( Coord, self->vertexCount, "vertexList" );
+ memcpy( newEquationShape->vertexList , self->vertexList, sizeof(Coord) * self->vertexCount );
+
+ newEquationShape->vertexList = self->vertexList;
+ newEquationShape->vertexCount = self->vertexCount;
+ memcpy( newEquationShape->start, self->start, sizeof(XYZ) );
+ memcpy( newEquationShape->end, self->end, sizeof(XYZ) );
+
+ return (void*)newEquationShape;
+}
+
+void* _EquationShape_DefaultNew( Name name ) {
+ /* Variables set in this function */
+ SizeT _sizeOfSelf = sizeof(EquationShape);
+ Type type = EquationShape_Type;
+ Stg_Class_DeleteFunction* _delete = _EquationShape_Delete;
+ Stg_Class_PrintFunction* _print = _EquationShape_Print;
+ Stg_Class_CopyFunction* _copy = _EquationShape_Copy;
+ Stg_Component_DefaultConstructorFunction* _defaultConstructor = _EquationShape_DefaultNew;
+ Stg_Component_ConstructFunction* _construct = _EquationShape_AssignFromXML;
+ Stg_Component_BuildFunction* _build = _EquationShape_Build;
+ Stg_Component_InitialiseFunction* _initialise = _EquationShape_Initialise;
+ Stg_Component_ExecuteFunction* _execute = _EquationShape_Execute;
+ Stg_Component_DestroyFunction* _destroy = _EquationShape_Destroy;
+ Stg_Shape_IsCoordInsideFunction* _isCoordInside = _EquationShape_IsCoordInside;
+ Stg_Shape_CalculateVolumeFunction* _calculateVolume = _EquationShape_CalculateVolume;
+ Stg_Shape_DistanceFromCenterAxisFunction* _distanceFromCenterAxis = _EquationShape_DistanceFromCenterAxis;
+
+ /* Variables that are set to ZERO are variables that will be set either by the current _New function or another parent _New function further up the hierachy */
+ AllocationType nameAllocationType = NON_GLOBAL /* default value NON_GLOBAL */;
+
+ return (void*) _EquationShape_New( POLYGONSHAPE_PASSARGS );
+}
+
+
+void _EquationShape_AssignFromXML( void* polygon, Stg_ComponentFactory* cf, void* data ) {
+ EquationShape* self = (EquationShape*)polygon;
+ Index vertexCount;
+ Index vertex_I;
+ Coord_List vertexList;
+ XYZ start;
+ XYZ end;
+ Axis perpendicularAxis;
+ char* perpendicularAxisName;
+ double* coord;
+ Dictionary_Entry_Value* optionSet;
+ Dictionary_Entry_Value* optionsList;
+ Dictionary* dictionary = Dictionary_GetDictionary( cf->componentDict, self->name );
+ Stream* stream = cf->infoStream;
+ Stream* errorStream = Journal_Register( Error_Type, (Name)self->type );
+
+ _Stg_Shape_AssignFromXML( self, cf, data );
+
+ start[I_AXIS] = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"startX", 0.0 );
+ end[I_AXIS] = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"endX", 0.0 );
+ start[J_AXIS] = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"startY", 0.0 );
+ end[J_AXIS] = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"endY", 0.0 );
+ start[K_AXIS] = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"startZ", 0.0 );
+ end[K_AXIS] = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"endZ", 0.0 );
+
+ perpendicularAxisName = Stg_ComponentFactory_GetString( cf, self->name, (Dictionary_Entry_Key)"perpendicularAxis", "z" );
+ switch ( perpendicularAxisName[0] ) {
+ case 'x': case 'X': case 'i': case 'I': case '0':
+ perpendicularAxis = I_AXIS; break;
+ case 'y': case 'Y': case 'j': case 'J': case '1':
+ perpendicularAxis = J_AXIS; break;
+ case 'z': case 'Z': case 'k': case 'K': case '2':
+ perpendicularAxis = K_AXIS; break;
+ default:
+ Journal_Firewall( False, Journal_Register( Error_Type, (Name)self->type ),
+ "Cannot understand perpendicularAxis '%s'\n", perpendicularAxisName );
+ }
+ if( self->dim == 3 && ( start[perpendicularAxis] == 0 && end[perpendicularAxis] == 0 ) ) {
+ Journal_Firewall( False, Journal_Register( Error_Type, (Name)self->type ),
+ "Problem with %s.\n"
+ "You've set the perpendicular axis to be %s, but you've not given the polygon any depth in that axis\n",
+ self->name, perpendicularAxisName );
+ }
+
+ optionsList = Dictionary_Get( dictionary, (Dictionary_Entry_Key)"vertices" );
+
+ vertexCount = Dictionary_Entry_Value_GetCount(optionsList );
+ Journal_Firewall( vertexCount >= 3, errorStream,
+ "Too few vertices given in trying to build shape '%s' named '%s'.\n"
+ "A polygon needs at least three vertices.\n",
+ self->type, self->name );
+
+ /* Allocate space */
+ vertexList = Memory_Alloc_Array( Coord , vertexCount, "Vertex Array" );
+ memset( vertexList, 0, vertexCount * sizeof(Coord) );
+
+ Stream_Indent( stream );
+ for ( vertex_I = 0 ; vertex_I < vertexCount ; vertex_I++) {
+ optionSet = Dictionary_Entry_Value_GetElement(optionsList, vertex_I );
+ coord = vertexList[vertex_I];
+ /* Read Vertex */
+ if( perpendicularAxis != I_AXIS )
+ coord[ I_AXIS ] = Dictionary_Entry_Value_AsDouble( Dictionary_Entry_Value_GetMember( optionSet, (Dictionary_Entry_Key)"x"));
+ if( perpendicularAxis != J_AXIS )
+ coord[ J_AXIS ] = Dictionary_Entry_Value_AsDouble( Dictionary_Entry_Value_GetMember( optionSet, (Dictionary_Entry_Key)"y"));
+ if( perpendicularAxis != K_AXIS )
+ coord[ K_AXIS ] = Dictionary_Entry_Value_AsDouble( Dictionary_Entry_Value_GetMember( optionSet, (Dictionary_Entry_Key)"z") );
+
+ /* Print Position */
+ Journal_PrintfL( stream, 2, "(%0.3g, %0.3g, %0.3g)\n", coord[I_AXIS], coord[J_AXIS], coord[K_AXIS] );
+ }
+ Stream_UnIndent( stream );
+
+ _EquationShape_Init( self, vertexList, vertexCount, start, end, perpendicularAxis );
+
+ Memory_Free( vertexList );
+}
+
+void _EquationShape_Build( void* polygon, void* data ) {
+ EquationShape* self = (EquationShape*)polygon;
+
+ _Stg_Shape_Build( self, data );
+}
+void _EquationShape_Initialise( void* polygon, void* data ) {
+ EquationShape* self = (EquationShape*)polygon;
+
+ _Stg_Shape_Initialise( self, data );
+}
+void _EquationShape_Execute( void* polygon, void* data ) {
+ EquationShape* self = (EquationShape*)polygon;
+
+ _Stg_Shape_Execute( self, data );
+}
+void _EquationShape_Destroy( void* polygon, void* data ) {
+ EquationShape* self = (EquationShape*)polygon;
+
+ Coord_List vertexList = self->vertexList;
+ Memory_Free( vertexList );
+
+ _Stg_Shape_Destroy( self, data );
+}
+
+/*--------------------------------------------------------------------------------------------------------------------------
+** Public Functions
+*/
+
+/*---------------------------------------------------------------------------------------------------------------------
+** Private Member functions
+*/
+/* Algorithm describe Paul Bourke's page http://astronomy.swin.edu.au/~pbourke/geometry/insidepoly/ (see solution 2)
+ *
+ * Algorithm works by summing the angles between the test coordinate and each pair of vertices that make up an edge
+ * in the polygon. An inside point will give an angle of 2pi and and outside point will give an angle of 0 */
+
+Bool _EquationShape_IsCoordInside( void* polygon, const Coord coord ) {
+ EquationShape* self = (EquationShape*) polygon;
+ Index vertexCount = self->vertexCount;
+ Coord_List vertexList = self->vertexList;
+ Axis perpendicularAxis = self->perpendicularAxis;
+ XYZ vectorToStartVertex = { 0.0, 0.0, 0.0 };
+ XYZ vectorToEndVertex = { 0.0, 0.0, 0.0 };
+ XYZ crossproduct = { 0.0, 0.0, 0.0 };
+ double currAngle;
+ double totalAngle = 0.0;
+ Index vertex_I;
+ double* startVertex;
+ double* endVertex;
+ Coord newCoord;
+
+ /* Transform coordinate into canonical reference frame */
+ Stg_Shape_TransformCoord( self, coord, newCoord );
+
+ /* Check to make sure that the coordinate is within startZ and endZ in 3D */
+ if ( self->dim == 3 && ( newCoord[ perpendicularAxis ] < self->start[perpendicularAxis] || newCoord[ perpendicularAxis ] > self->end[perpendicularAxis] ))
+ return False;
+
+ for ( vertex_I = 0 ; vertex_I < vertexCount ; vertex_I++ ) {
+ /* Get vertices of current edge */
+ startVertex = vertexList[ vertex_I ];
+ endVertex = vertexList[ (vertex_I + 1) % vertexCount ];
+
+ /* Work out vectors */
+ StGermain_VectorSubtraction( vectorToStartVertex, newCoord, startVertex, 3 );
+ StGermain_VectorSubtraction( vectorToEndVertex, newCoord, endVertex, 3 );
+
+ vectorToStartVertex[ perpendicularAxis ] = 0;
+ vectorToEndVertex[ perpendicularAxis ] = 0;
+
+ /* Work out angle - just by doing dot product - will always be positive */
+ currAngle = StGermain_AngleBetweenVectors( vectorToStartVertex, vectorToEndVertex, 3 );
+
+ /* Work out 'sign' of angle but working out cross product */
+ StGermain_VectorCrossProduct( crossproduct, vectorToEndVertex, vectorToStartVertex );
+
+ if ( crossproduct[ perpendicularAxis ] > 0.0 )
+ totalAngle += currAngle;
+ else
+ totalAngle -= currAngle;
+ }
+
+
+ /* work out whether the coord is within the polygon */
+ if ( fabs( totalAngle ) < M_PI )
+ return False;
+ else
+ return True;
+}
+
+
+double _EquationShape_CalculateVolume( void* polygon ) {
+ assert( 0 );
+ return 0.0;
+}
+
+void _EquationShape_DistanceFromCenterAxis( void* shape, const Coord coord, double* disVec ){
+ Stg_Shape* self = (Stg_Shape*)shape;
+ Journal_Firewall( False, Journal_Register( Error_Type, (Name)self->type ),
+ "Error in function %s: This functions hasn't been implemented.",
+ "Please inform underworld-dev at vpac.org you've received this error.\n", __func__ );
+}
+
+
+
diff -r ae3bb598eb97 -r 56dbfba1e984 Shape/src/EquationShape.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Shape/src/EquationShape.h Wed Nov 09 00:54:58 2011 -0800
@@ -0,0 +1,113 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+** Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+** Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+** Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+** Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+** Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+** Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+** This library is free software; you can redistribute it and/or
+** modify it under the terms of the GNU Lesser General Public
+** License as published by the Free Software Foundation; either
+** version 2.1 of the License, or (at your option) any later version.
+**
+** This library is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+** Lesser General Public License for more details.
+**
+** You should have received a copy of the GNU Lesser General Public
+** License along with this library; if not, write to the Free Software
+** Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+**
+*/
+/** \file
+** Role:
+**
+** Assumptions:
+**
+** Comments:
+**
+** $Id: EquationShape.h 3851 2006-10-12 08:57:22Z SteveQuenette $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#ifndef __StgDomain_Shape_EquationShapeClass_h__
+#define __StgDomain_Shape_EquationShapeClass_h__
+
+ /* Textual name of this class */
+ extern const Type EquationShape_Type;
+
+ /* EquationShape information */
+ #define __EquationShape \
+ /* General info */ \
+ __Stg_Shape \
+ /* Virtual Info */\
+ \
+ char *equation;
+
+ struct EquationShape { __EquationShape };
+
+
+ /*---------------------------------------------------------------------------------------------------------------------
+ ** Constructors
+ */
+ EquationShape* EquationShape_New(
+ Name name,
+ Dimension_Index dim,
+ XYZ centre,
+ double alpha,
+ double beta,
+ double gamma,
+ char* equation);
+
+
+ #ifndef ZERO
+ #define ZERO 0
+ #endif
+
+ #define EQUATIONSHAPE_DEFARGS \
+ STG_SHAPE_DEFARGS
+
+ #define EQUATIONSHAPE_PASSARGS \
+ STG_SHAPE_PASSARGS
+
+ EquationShape* _EquationShape_New( EQUATIONSHAPE_DEFARGS );
+
+ void _EquationShape_Init( void* sphere, char *equation ) ;
+
+ /* Stg_Class_Delete EquationShape implementation */
+ void _EquationShape_Delete( void* sphere );
+ void _EquationShape_Print( void* sphere, Stream* stream );
+ #define EquationShape_Copy( self ) \
+ (EquationShape*) Stg_Class_Copy( self, NULL, False, NULL, NULL )
+ #define EquationShape_DeepCopy( self ) \
+ (EquationShape*) Stg_Class_Copy( self, NULL, True, NULL, NULL )
+ void* _EquationShape_Copy( const void* sphere, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap );
+
+ void* _EquationShape_DefaultNew( Name name ) ;
+ void _EquationShape_AssignFromXML( void* shape, Stg_ComponentFactory* cf, void* data ) ;
+ void _EquationShape_Build( void* sphere, void* data ) ;
+ void _EquationShape_Initialise( void* sphere, void* data ) ;
+ void _EquationShape_Execute( void* sphere, void* data );
+ void _EquationShape_Destroy( void* sphere, void* data ) ;
+
+ Bool _EquationShape_IsCoordInside( void* sphere, const Coord coord ) ;
+ void _EquationShape_DistanceFromCenterAxis( void* sphere, const Coord coord, double* disVec );
+ double _EquationShape_CalculateVolume( void* sphere );
+
+ /*---------------------------------------------------------------------------------------------------------------------
+ ** Public member functions
+ */
+
+ /*---------------------------------------------------------------------------------------------------------------------
+ ** Private Member functions
+ */
+
+
+#endif
+
diff -r ae3bb598eb97 -r 56dbfba1e984 Shape/src/EquationShape.meta
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Shape/src/EquationShape.meta Wed Nov 09 00:54:58 2011 -0800
@@ -0,0 +1,34 @@
+<?xml version="1.0"?>
+<!DOCTYPE StGermainData SYSTEM "stgermain.dtd">
+<StGermainData xmlns="http://www.vpac.org/StGermain/XML_IO_Handler/Jun2003">
+
+<param name="Name">EquationShape</param>
+<param name="Author">...</param>
+<param name="Organisation">CIG</param>
+<param name="Project">StgDomain</param>
+<param name="Location">./StgDomain/Shape/src/</param>
+<param name="Project Web">http://geodynamics.org</param>
+<param name="Copyright">StGermain Framework. Copyright (C) 2003-2005 VPAC.</param>
+<param name="License">The Gnu Lesser General Public License v2.1 - http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html</param>
+<param name="Parent">Stg_Shape</param>
+<param name="Reference">...</param>
+<param name="Summary">...</param>
+<param name="Description">Constructs a shape where the boundary is determined by whether an equation is positive or negative. </param>
+
+<!--Now the interesting stuff-->
+
+
+<list name="Params">
+ <struct>
+ <param name="Name">equation</param>
+ <param name="Type">char</param>
+ <param name="Default">N/A</param>
+ <param name="Description">The equation defining the inside and outside of the shape.</param>
+ </struct>
+</list>
+
+<list name="Dependencies">
+</list>
+<!-- Add an exmaple XML if possible -->
+
+</StGermainData>
diff -r ae3bb598eb97 -r 56dbfba1e984 Shape/src/Init.cxx
--- a/Shape/src/Init.cxx Wed Nov 09 00:54:46 2011 -0800
+++ b/Shape/src/Init.cxx Wed Nov 09 00:54:58 2011 -0800
@@ -48,6 +48,7 @@ Bool StgDomainShape_Init( int* argc, cha
Stg_ComponentRegister_Add( componentRegister, ConvexHull_Type, (Name)"0", _ConvexHull_DefaultNew );
Stg_ComponentRegister_Add( componentRegister, Sphere_Type, (Name)"0", _Sphere_DefaultNew );
Stg_ComponentRegister_Add( componentRegister, PolygonShape_Type, (Name)"0", _PolygonShape_DefaultNew );
+ Stg_ComponentRegister_Add( componentRegister, EquationShape_Type, (Name)"0", _EquationShape_DefaultNew );
Stg_ComponentRegister_Add( componentRegister, Union_Type, (Name)"0", _Union_DefaultNew );
Stg_ComponentRegister_Add( componentRegister, Intersection_Type, (Name)"0", _Intersection_DefaultNew );
Stg_ComponentRegister_Add( componentRegister, Cylinder_Type, (Name)"0", _Cylinder_DefaultNew );
@@ -66,7 +67,8 @@ Bool StgDomainShape_Init( int* argc, cha
RegisterParent( Everywhere_Type, Stg_Shape_Type );
RegisterParent( ConvexHull_Type, Stg_Shape_Type );
RegisterParent( Sphere_Type, Stg_Shape_Type );
- RegisterParent( PolygonShape_Type, Stg_Shape_Type );
+ RegisterParent( PolygonShape_Type, Stg_Shape_Type );
+ RegisterParent( EquationShape_Type, Stg_Shape_Type );
RegisterParent( Union_Type, Stg_Shape_Type );
RegisterParent( Intersection_Type, Stg_Shape_Type );
RegisterParent( Cylinder_Type, Stg_Shape_Type );
diff -r ae3bb598eb97 -r 56dbfba1e984 Shape/src/Shape.h
--- a/Shape/src/Shape.h Wed Nov 09 00:54:46 2011 -0800
+++ b/Shape/src/Shape.h Wed Nov 09 00:54:58 2011 -0800
@@ -47,6 +47,7 @@
#include "Sphere.h"
#include "Everywhere.h"
#include "PolygonShape.h"
+ #include "EquationShape.h"
#include "Union.h"
#include "Intersection.h"
#include "PythonShape.h"
diff -r ae3bb598eb97 -r 56dbfba1e984 Shape/src/types.h
--- a/Shape/src/types.h Wed Nov 09 00:54:46 2011 -0800
+++ b/Shape/src/types.h Wed Nov 09 00:54:58 2011 -0800
@@ -48,7 +48,8 @@
typedef struct Everywhere Everywhere;
typedef struct Box Box;
typedef struct Sphere Sphere;
- typedef struct PolygonShape PolygonShape;
+ typedef struct PolygonShape PolygonShape;
+ typedef struct EquationShape EquationShape;
typedef struct Union Union;
typedef struct Intersection Intersection;
typedef struct ConvexHull ConvexHull;
More information about the CIG-COMMITS
mailing list