/Users/craigcornelius/Projects/SPRING Mac Release 0.2/object.h

Go to the documentation of this file.
00001 // $Id: object.h,v 1.160 2006/02/28 03:20:19 hawaii Exp $
00002 // $Copyright: (c)2001 National Biocomputation Center, Stanford University $
00003 
00004 #ifndef Object_Header
00005 #define Object_Header
00006 
00007 #include "glui.h"
00008 
00009 #include "nodearray.h"
00010 #include "edgearray.h"
00011 #include "facearray.h"
00012 #include "tetraarray.h"
00013 #include "sensor.h"
00014 #include "reallocablearray.h"
00015 #include "geometryreplicator.h"
00016 #include "boundingsphere.h"
00017 #include "boundingbox.h"
00018 #include "displaymode.h"
00019 #include "socket.h"
00020 #include "timer.h"
00021 #include "util.h"
00022 #include "texture.h"
00023 
00024 class ObjectArray;
00025 class Sensor;
00026 class BoundingSphereNode;
00027 
00028 
00029 typedef struct{
00030     Node* node;
00031     double test;
00032 } testCell;
00033 
00034 typedef struct {                // BOUNDING_SPHERE collision detection 
00035     BoundingSphereLeaf* mySphere;
00036     BoundingSphereLeaf* otherSphere;
00037     Object* colObj;             // seems to always be unused???
00038     Point3D int_pt;
00039     double near1;               // these are parameters for nearest point of 2 edges
00040     double near2;
00041     double dist;                // and distance between 2 edges
00042 } Collision_pair;
00043 
00044 typedef struct CollisionBoxPairStruct {         // AABB collision detection
00045         BoundingBox* myCollisionBox;
00046         BoundingBox* otherCollisionBox;
00047 } CollisionBoxPair;
00048 
00049 typedef struct {
00050     int                 node_index; // node index to rotate around
00051     int         sensor_index;
00052     Point3D     rotation_vector; // vector to rotate around
00053     double      max_open; // maxiumum rotation to open around this vector
00054     double      max_closed; // maximum rotation to close around this vector
00055     int                 colors_pos[3]; // what color in the nodearray do this rotation
00056     int                 colors_neg[3]; // what color in the nodearray do this rotation
00057 } hinge;
00058 
00059 typedef struct {
00060         Point3D hingeVector;                    // vector to rotate around
00061         int hingeNodeIndex;                             // index of a node in the hinge (needs to be tied to other obj)
00062         int     moveHingeNodeIndex;                     // index of a node which is not in the hinge
00063         Point3D hingeAngleVector;               // 0 degree vector used for min/max angle
00064         float minHingeAngle;                    // minimum angle in respect to moveHingeNodeIndex & hingeAngleVector
00065         float maxHingeAngle;                    // maximum angle in respect to moveHingeNodeIndex & hingeAngleVector
00066 } RigidHinge;
00067 
00068 
00069 class Object {
00070 public:
00071     // most objects are physical (obey lighting),some are virtual (thread,cursor)
00072     Object();
00073     ~Object();
00074     static const char* rcsid;
00075     static int debug;
00076     
00077     // useful enums
00078     enum object_type {nodes_only, edges_only, faces_only, tetras_only};
00079     enum dynamics_type {rest, rigid, deformable, articulate, button};
00080     enum behavior_type {none, grabbing, cutting, deleting, poking, 
00081                 ablating, cauterizing, coloring, quisar_test, dilating, beating, fluid};
00082     enum numerical_method {euler, euler_ordered, runge, runge_4thorder, quasi,
00083         quasi_ordered, bogus, FSA, FSAF};
00084     enum collision_extent_type {no_collisions, external, 
00085         internal, internal_external};
00086         enum collision_force_type {normal_force, penetration_depth_force};
00087     enum texture_env_mode {modulate, blend, decal, replace};
00088     enum texture_wrap_st {repeat, clamp};
00089     enum texture_min_mag_filter {linear, nearest};
00090     
00091     // Collisions
00092     void setCollisionExtent(collision_extent_type extent);
00093     collision_extent_type getCollisionExtent();
00094         void setCollisionForce(collision_force_type collision_force_) { collision_force = collision_force_; }
00095         collision_force_type getCollisionForce() { return collision_force; }
00096         ReallocableArray<Face*> getCollisionFaces() { return collision_faces; }
00097 
00098         void ConstructCollisions();
00099         void DestructCollisions();
00100     void ResetCollisions();
00101     void DetectCollisions(Object* other_obj);
00102     void MarkCollisions();
00103     void ResolveCollisions();
00104     bool CollidesWith(Object* other_obj);
00105 
00106     Point3D CalculateForce(Face* myFace, Face* otherFace);
00107     void addEverythingToUpdateList();
00108     
00109         // BOUNDING_SPHERE_CD stuff
00110     BoundingSphereNode* getBoundingSphereRoot();
00111                 void setBoundingSphereRoot(BoundingSphereNode* rt);
00112                 
00113     void CreateSphereTree();
00114     void DestroySphereTree();
00115     
00116     void addToSphereTree(Face* face);
00117     void removeFromSphereTree(Face* face);
00118         void addToSphereTree(Tetra* tetra);
00119     void removeFromSphereTree(Tetra* tetra);
00120     
00121         void removeFromCollisionPairs(Face* me);
00122         void removeFromCollisionPairs(Tetra* me);
00123     
00124     void addToUpdateList(Edge* addedge);
00125     void addToUpdateList(Face* addface);
00126     void addToUpdateList(Tetra* addtetra);
00127     
00128     int ResolveFaceFaceCollisions(Collision_pair* c_p, 
00129         Point3D* this_haptic_force_p);
00130     void ResolveEdgeEdgeCollisions(Collision_pair* c_p);
00131     
00132     int  getNumTotalCollisions();
00133     void findNodeNodeCollisions(Object* other);
00134     void findNodeEdgeCollisions(Object* other);
00135     void findNodeFaceCollisions(Object* other);
00136     void findNodeTetraCollisions(Object* other);
00137     void findEdgeEdgeCollisions(Object* other);
00138     void findEdgeFaceCollisions(Object* other);
00139     void findEdgeTetraCollisions(Object* other);
00140     void findFaceFaceCollisions(Object* other);
00141     void findFaceTetraCollisions(Object* other);
00142     void findTetraTetraCollisions(Object* other);
00143 
00144         void CollisionPairAdd(Collision_pair pair);
00145         int CollisionPairGetNumElements();
00146         Collision_pair CollisionPairGet(int i);
00147     
00148         // AABB_CD collision detection algorithm
00149         BoundingBox* getBoundingBoxRoot() { return boundingBoxRoot; }
00150         void setBoundingBoxRoot(BoundingBox* boundingBoxRoot_) { boundingBoxRoot = boundingBoxRoot_; }
00151         bool isDoBoundingBoxRootUpdate() { return doBoundingBoxRootUpdate; }
00152         void setDoBoundingBoxRootUpdate(bool doUpdate_) { doBoundingBoxRootUpdate = doUpdate_; }
00153         int getMaxLevelCollisionCheck() { return maxLevelCollisionCheck; }
00154         void setMaxLevelCollisionCheck(int maxLevel_) { maxLevelCollisionCheck = maxLevel_; }
00155 
00156     //
00157     // startup stuff
00158     //
00159     void Init(ObjectArray* objectarray_in, char* name);
00160     
00161     //
00162     // links to nodearray, edgearray, facearray
00163     //
00164     NodeArray* getNodeArray() { return(&nodearray); }
00165     EdgeArray* getEdgeArray() { return(&edgearray); }
00166     FaceArray* getFaceArray() { return(&facearray); }
00167         TetraArray* getTetraArray() { return(&tetraarray); }
00168     
00169     //
00170     // File I/O Routines
00171     //
00172     int Read(char* filename);
00173     int Read(char* dirname_part, char* filename_part);
00174     int ReadAmira(FILE *fp);
00175     int ReadMesh(FILE* fp);
00176     int ReadSMF(FILE* fp);
00177     int ReadOBJ(FILE* fp);
00178     int ReadSOBJ(FILE* fp);       // Spring-OBJ -> to create object internally already defined, such as sphere
00179     int ReadFRD(FILE* fp);
00180     int ReadVRML(FILE* fp, int create_subobjects=1);
00181                 int ReadVRMLObject(FILE* fp, Matrix original_xform, int create_subobjects=1, int is_vrml2=0);
00182     int ReadCyberware(FILE* fp);
00183     void ParseAttribute(char* line);    // for reading in .desc file attributes
00184     
00185     //
00186     
00187     // Spontaneous generation routines
00188     //
00189     
00190     void CreateThread(double length, double node_spacing, int orientation, 
00191         Point3D offset, double edgethresh_in = 0.10, int first_seg = 0);
00192     void CreateEdgeRing(Point3D center, double radius, int numedges,
00193                                 double edgethresh_in);
00194     void CreateTestLine(int num_segs, double length, Point3D offset,int fix_end);
00195     void CreateEquiMesh(int numlevels, double edgelength);
00196     void CreateTube(char orientation, int num_radii, int num_rings, double radius, 
00197         double length, Point3D offset, int diag1 = 0, int diag2 = 0,
00198         int fix_num = 0, double inner_radius = -1.0,
00199         int cross1 = 0, int cross2 = 0, int capped = 0,
00200         double sc1 = 1.0, double sc2 = 1.0, double rl_out = -1.0, 
00201         double rl_in = -1.0, double rl_betw = -1.0);
00202     int CreateSphere(int numlayers, double radius, double inner = -1.0);
00203     void CreatePlane(double x_length, double y_length, int x_steps, int y_steps,
00204         Point3D offset, char orientation = 'z');
00205     void CreateForcep(double length, double width);
00206     void CreateHexSurfaceDeformedMenu(void);
00207     void CreateHexSurfaceDeformed(void);
00208     void CreateEndoscope(double length);
00209     void CreateNeedle(double length, double width, Point3D offset);
00210     void CreateGrabby(double length, double width, Point3D offset);
00211     void CreateCutterTool(float scalefactor);
00212     void CreatePlaneTool(double width, double height, Point3D offset);
00213     void CreateBox(double width, double height, double depth);
00214     void CreateBox2(int xlayers, int ylayers, int zlayers, double length,
00215         int outlayers, double sc_out=0, double sc_in=0);
00216     void CreateNodeCloud(int num_nodes, int radius, Point3D offset);
00217     
00218     // 
00219     //Generally Useful Stuff
00220     //
00221     int uses_viagra;
00222     
00223     Node* closest_node;                            // closest node of object we are affecting
00224     int being_grabbed;                             // are we currently being grabbed?
00225     float prev_grabbing_activation;    // activation for sensor when we tried to grab last
00226 
00227     char* getName();
00228         char* getPath();    // returns the path if available
00229     char* getChildName(void);
00230     void setName(char* new_name);
00231         void setPath(char* filepath);  // sets the file path excl. filename to the file if any
00232     void setChildName(char* new_child_name);
00233 
00234     // used by FSA algorithm
00235     double getTime();
00236     void resetTimer();  
00237     
00238     ObjectArray* getObjectArray();
00239     
00240     void setType(object_type t);
00241     object_type getType();
00242     Point3D getCenter();
00243     double getRadius();
00244     
00245     void Select();
00246     void Unselect();
00247     
00248     void SetVisible(int on);
00249     int  isVisible();
00250     
00251     int IsAScreen;
00252     
00253     //
00254     // bounding box and sphere stuff, old
00255     //
00256     int intersectsBoundingSphere(Object* test_obj);
00257     void getBoundingBox(Point3D* min_p, Point3D* max_p);
00258     int intersectsBoundingBox(Object *obj, double e=0.0);
00259     double distanceToBoundingBox(Point3D pt);
00260     
00261     // 
00262     // texture stuff
00263     //
00264     void setTexture(char* filename = NULL);  // NULL = use name of object.rgb
00265     void setTextureCoords(Node::texture_coord_type t);
00266     unsigned char* getTexture();
00267     void moveTexture(Point3D translation, Point3D scaling);
00268     texture_wrap_st getTextureWrap() { return texture_wrap; }
00269     void setTextureWrap(texture_wrap_st texture_wrap_) { texture_wrap = texture_wrap_; }
00270 
00271     //
00272     // object properties
00273     // 
00274     dynamics_type getDynamics();
00275     void setDynamics(dynamics_type d);
00276 
00277     double getEdgeThresh();
00278 
00279     behavior_type getBehavior();
00280     void setBehavior(behavior_type b);
00281     
00282     numerical_method getNumMethod();
00283     void setNumMethod(numerical_method n);
00284     
00285     void setAmbientColor(float red, float green, float blue, float alpha);
00286     float* getAmbientColor();
00287     void setDiffuseColor(float red, float green, float blue, float alpha);
00288     float* getDiffuseColor();
00289     void setSpecularColor(float red, float green, float blue, float alpha);
00290     float* getSpecularColor();
00291     void setShininess(float s);
00292     float* getShininess();
00293     
00294     void setBackAmbientColor(float red, float green, float blue, float alpha);
00295     float* getBackAmbientColor();
00296     void setBackDiffuseColor(float red, float green, float blue, float alpha);
00297     float* getBackDiffuseColor();
00298     void setBackSpecularColor(float red, float green, float blue, float alpha);
00299     float* getBackSpecularColor();
00300     void setBackShininess(float s);
00301     float* getBackShininess();
00302     
00303     DisplayMode getDisplayMode();
00304     void setDisplayMode(DisplayMode dm_in);
00305 
00306         void setObjectWeight(double w);
00307         double getObjectWeight();
00308     
00309     // label stuff
00310     void setLabelOffset(float new_lo);
00311     
00312     void PrintInfo();
00313     friend ostream& operator<<(ostream& os, Object& o);
00314     
00315     //
00316     // Core functionality
00317     //
00318     void getPosAngle(Point3D* pos_p, Point3D* rot_p);
00319     
00320     double getVolume();
00321     double getSurfaceArea();
00322     
00323     void setExtrusionParameters(double exlength, int Nb_ex, int extype, 
00324         int algo, int facesOutside, int facesLayers, int fixLastLayer,
00325         int Nb_face_surf, int Nb_pts_surf, int Nb_edge_surf);
00326         void getExtrusionParameters(double* exlength, int* Nb_ex, int* extype, 
00327         int* algo, int* facesOutside, int* facesLayers, int* fixLastLayer,
00328         int* Nb_face_surf, int* Nb_pts_surf, int* Nb_edge_surf);
00329     int getNb_Face_Surf();
00330     
00331     void ForceDisplayUpdate();
00332     
00333     void flipFaces();
00334     
00335     void Update();
00336     void tipUpdate();   // for keeping track of motion delta
00337     
00338     int getGroupNumber();
00339     void setGroupNumber(int group);
00340     
00341     // drawing
00342     void Draw();
00343     void DrawGeometry();
00344     void DrawBoundingBox();
00345     void DrawLabel();
00346         void DrawPrincipalAxes();
00347     void GeometryReplicate(GeometryReplicator* gr);
00348     
00349     Node* findClosestNode(Point3D pt);
00350     double findClosestNodesBetweenObjects(Object* other_obj, Node** our_node_p,
00351         Node** other_node_p);
00352     
00353     void ShrinkWrap(Object* other_obj);
00354     
00355     void ElasticAdjustment(ObjectArray* universe_p, Object* current_object);
00356     
00357     void TieNode0(Object* other_obj);
00358     void TieObject(Object* other_obj);
00359     
00360     void Join(Object* other_obj);
00361     void MergeSubparts(double dist);
00362     
00363     void ExtrusionMenu(void);
00364     void PerformExtrusion(int glui_p);
00365     void Extrusion(Object* obj);
00366     
00367     // exporting
00368     void SaveAsAmira(ostream& os);
00369     void SaveAsMesh(ostream& os);
00370     void SaveAsFRD(ostream& os);
00371     void SaveAsSMF(ostream& os);
00372     void SaveAsDXF(ostream& os);
00373     void SaveAsVRML1(ostream& os);
00374     void SaveAsVRML2(ostream& os);
00375     void SaveAsSTL(ostream& os);
00376     
00377     // behaviors/collisions
00378     void HandleBehavior();
00379         void HandleInteractiveBehavior();
00380         void HandleSpontaneousBehavior();
00381         void setDoDeformOnlyOnGrab(int i);
00382         void PreserveVolume();
00383     
00384     // movement/repositioning
00385     void CenterObject();
00386     void Move(Point3D motion_vector);
00387     
00388     // coloring/subobjects
00389     int ColorConnectedComponents();
00390     int SpreadOutColor();
00391     void ResetColors(int color = 0);
00392     void SplitColor(Object* tool);
00393     void SplitPieces();
00394     void DeleteNodesOfColor(int color);
00395     void ColorFacesUsingMarkers(int color, Node** markers, int nummarkers);
00396     void FillInColors(int color);
00397     void FixNodesOfColor(int color);
00398     void ColorNodesWithinBoundingBox(Point3D min, Point3D max, int color);
00399     
00400     void ReflectMesh(int axis, double value);
00401     
00402     // path ops
00403     int WalkGreedyPathUsingNodes(Node* start, Node* end, Node** path, int max);
00404     void DuplicatePath(Node** path, int num_nodes_on_path);
00405     void ColorPath(int color, Node** path, int num_nodes_on_path);
00406     
00407     void SanityCheck();
00408     void Cleanup();
00409     
00410     double CumulativeDistanceBetweenObjects(Object* obj_p);
00411     
00412     void RegisterToGivenObject(Object* obj_p);
00413     
00414     void Scale(double value);
00415     void ScaleByNormal(double value);
00416     
00417     void ReorderFacesBasedOnViewer();
00418     void Refresh();
00419     void Spread(double kx, double ky, double kz);
00420     void Translate(double kx, double ky, double kz);
00421     void Rotate90() {nodearray.rotate90();}
00422     void Rotate(int axis = 0, double t = PI/2);
00423     
00424     // 
00425     // Functions for objects attached to sensors
00426     //
00427     void LinkToSensor(Sensor* sensor_p); // object is linked to given sensor
00428     int isLinked();    // is the object linked to a sensor?
00429     Sensor* getSensor();
00430     Point3D getSensorOffset();
00431     void setSensorOffset(Point3D offset); // sensor pos w.r.t. center of obj
00432     
00433     // for grabbing
00434     Point3D getTip();
00435     void setTip(int index);
00436     Point3D getTipDelta();
00437 
00438         // for fluids (to set the fluid height over ground level 0)
00439         double getHeight();
00440         void setHeight(double height);
00441 
00442     // for having subparts move separately
00443     int getLinkedPart();
00444     void setLinkedPart(int lp);
00445     
00446     // for hinges
00447     Point3D getHingePoint();
00448     void setHingePoint(Point3D p);
00449     void setMaxOpen(Point3D angles);
00450     void setMaxClosed(Point3D angles);
00451     void addToHinges(int si, int ai, Point3D r, double maxopen, double maxclosed, 
00452         int col0, int col1, int col2);
00453     
00454         // for rigid object hinges
00455         RigidHinge* getRigidHinge();
00456         void setRigidHinge(RigidHinge* newRigidHinge);
00457         float getRigidHingeAngle(); 
00458 
00459     // link subpart only
00460     void LinkSubpartToSensor(int subpart, Sensor* sensor_p); 
00461     
00462     // for transforming an object's parts
00463     void xformHingedObject();
00464     void xformObject();
00465         void xformCopies(ReallocableArray<Point3D> &tempnodepos, ReallocableArray<int> tempnodecol, int part, Matrix m, 
00466         Point3D center_offset, Point3D origin);
00467     
00468     
00469     // 
00470     // DECIMATION
00471     //
00472     static int TestCompare(const void* entry1, const void* entry2);
00473     void Decimation(int typeOfDecimation, int amountOfDecimation, double value);
00474     void Triangulate1(int n, Node* polygon[], Point3D normal, int faceIndex[]);
00475     void TriRecurse(int n, Node* polyInit[], Node* poly[], int labels[], 
00476         Point3D normal, int faceIndex[], int* numFace_p, int* test);
00477                 double EdgeStats();
00478                 void EdgeCollapse(double limit);
00479     
00480     // 
00481     // CUTTING
00482     //
00483     void CutUsingMarkers(Node** markers, int nummarkers);
00484     void CuttingByDeleting(Object *cutter);
00485     
00486     void        addToCuttingFaces(Face* face);
00487     Face* getCuttingFace(int index);
00488     int         numCuttingFaces();
00489     int         isACuttingFace(Face* you);
00490     
00491     void        addToCuttingEdges(Edge* edge);
00492     Edge* getCuttingEdge(int index);
00493     int         numCuttingEdges();
00494     int         isACuttingEdge(Edge* you);
00495     
00496     void        addToCutPath(Node* intersection);
00497     void        clearCutPath();
00498     int         numCutPath();
00499     Node* getCutPathNode(int index);
00500     
00501     int testEdge(Point3D entPt, Edge* myedge, Edge* you, int test);
00502     int testFace(Face* myface, Edge* you);
00503     
00504     int inCollisionWithMyCuttingEdges(Edge* other_edge);        
00505     int inCollisionWithMyCuttingEdges(Face* other_face);        
00506     int inCollisionWithMyCuttingFaces(Edge* other_edge);        
00507     int inCollisionWithMyCuttingFaces(Face* other_face);        
00508     
00509     void        addToLastFaces(Face* me);
00510     Face* getLastFace(int index);
00511     int         numLastFacesInCollision();      
00512     int         isInLastFaces(Face* me);        
00513     
00514     int testEdges(Face* me, Edge* you, int test);
00515     
00516     int updateFaceCutter(Face* me, Edge* you, int test);
00517     int moveFaceCutter(Face* me, Edge* you, int test);   
00518     int finishFace(Face* me);
00519     int CutFace(Face* me,int v[], int caseIdx);
00520     
00521     void        addToLastTetras(Tetra* me);
00522     Tetra*      getLastTetra(int index);
00523     int         numLastTetrasInCollision();     
00524     int         isInLastTetras(Tetra* me);      
00525     
00526     int updateTetraCutter(Tetra* me, Edge* you, int test);
00527     int moveTetraCutter(Tetra* me, Edge* you, int test);
00528     
00529     int finishTetra(Tetra* me);
00530     int CutTetra(Tetra* me, int v[], int caseIdx);
00531     
00532     
00533     // 
00534     //Menus
00535     //
00536     void Menu();
00537     
00538 protected:
00539     ObjectArray* objectarray_p;
00540     
00541     enum {NAME_LENGTH = 1024};
00542     enum {PATH_LENGTH = 1024};
00543     char name[NAME_LENGTH];
00544         char path[PATH_LENGTH];      // path to file if any (needed for texture loading)
00545     char child_name[NAME_LENGTH];
00546     
00547     object_type              type;
00548     dynamics_type            dynamics;
00549     double                   edgethresh; // thickness of edges
00550     behavior_type            behavior;
00551     numerical_method         nummethod;
00552     texture_env_mode         texture_mode;
00553     texture_wrap_st          texture_wrap;
00554     texture_min_mag_filter   texture_filter;
00555     collision_extent_type    collision_extent;
00556         collision_force_type     collision_force;   // type of force returned by this object
00557         ReallocableArray<Face*>  collision_faces;   // list of collisionfaces if any
00558         int                      being_modified;
00559     
00560 
00561     // my bounding sphere (BOUNDING_SPHERE_CD)
00562     BoundingSphereNode* boundingSphereRoot;
00563     int                         num_total_collisions;
00564     ReallocableArray<Face*>     cutting_faces;
00565     ReallocableArray<Edge*>     cutting_edges;
00566     ReallocableArray<Face*>         last_faces_in_collision;
00567     ReallocableArray<Tetra*>    last_tetras_in_collision;
00568     
00569         // Bounding box (for AABB_CD collision detection algorithm)
00570         BoundingBox* boundingBoxRoot;
00571         bool doBoundingBoxRootUpdate;
00572         int maxLevelCollisionCheck;                             // maximum level to check for collisions
00573         ReallocableArray<CollisionBoxPair>* collisionBoxPairs;
00574 
00575         // Info about a possibly connected sensor (does not apply to all objects)
00576     Sensor* sensor_p;          // what sensor we're linked to
00577     Point3D sensor_offset;     // sensor position on object w.r.t center
00578     int     linked_part;       // part of this object linked to the sensor
00579 
00580     // used by FSA algorithm
00581     Timer timer;
00582     
00583     ReallocableArray<hinge> hinges;     // for new-type hinged objects
00584     
00585     ReallocableArray<Node*> cutPath;
00586 
00587         // Bounding sphere collision pairs
00588         ReallocableArray<Collision_pair> collision_pairs;
00589 
00590     // for hinges on rigid objects (Chris) - used in nodearray.updateRigidNodes()
00591         RigidHinge* rigidHinge;
00592 
00593     // graphics stuff
00594     int visible;                  // is this object visible?
00595     int selected;                 // is this object selected?
00596     
00597     // for grabbing
00598     int tip_node;                            
00599     Point3D oldtip;
00600     Point3D tipdelta;     // for keeping track of object's motion
00601     Point3D oldbase;
00602     Point3D basedelta;    // for keeping track of object's motion
00603         int do_deform_only_on_grab;  // only deform when grabbed
00604         
00605         int do_preserve_volume; //volume preservation after deformation
00606     double original_volume;
00607 
00608     // for fluids (to set the fluid height over ground)
00609         double height;
00610 
00611     // Extrusion stuff
00612     int objextrusions;    // number of layers produced by the extrusion function
00613     int Nb_pts_surf, Nb_edge_surf, Nb_face_surf; // #s before any extrusion
00614     double exlength;
00615     int Nb_ex, extype, algo, facesOutside, facesLayers, fixLastLayer;
00616     
00617     // Hex surface stuff
00618     Point3D offset; int orient; double length; int n_width; double defcoef;
00619     
00620     // texture stuff
00621     unsigned char* texture;
00622     iPoint3D texture_size;
00623     
00624     // objects keep their own data now
00625     NodeArray nodearray;
00626     EdgeArray edgearray;
00627     FaceArray facearray;
00628     TetraArray tetraarray;
00629     
00630     // material properties
00631     float mat_ambient[4];
00632     float mat_diffuse[4];
00633     float mat_specular[4];
00634     float mat_shininess[1];
00635     
00636     float back_mat_ambient[4];
00637     float back_mat_diffuse[4];
00638     float back_mat_specular[4];
00639     float back_mat_shininess[1];
00640     
00641     float drawover_amount;
00642     float label_offset;
00643                 //mass distribution
00644                 double object_weight;
00645     
00646     // now we belong to a group
00647     int group_number;
00648     
00649     // for display-list graphics
00650     int dl_needs_refresh;
00651     int dl_id;
00652     DisplayMode display_mode;
00653     DisplayMode last_display_mode;
00654     
00655     // internal functions
00656     void set_default_material_properties();
00657     
00658     // menu callbacks and vars
00659     double new_mass, new_spring, new_damp, new_FSA;
00660     static void MSDChangedCB(int obj_p_in);
00661     
00662     static void TextureCoordCB(int obj_p_in);
00663     static void TextureModeCB(int obj_p_in);
00664     static void TextureWrapCB(int obj_p_in);
00665     static void TextureFilterCB(int obj_p_in);
00666     
00667     static void MenuValueChangedCB(int obj_p_in);
00668     static void TissueTypeCB(int obj_p_in);
00669     static void DampTypeCB(int obj_p_in);
00670     
00671     // We want to know the force that will result of a given node was in an
00672     // other position- used by the ForceGrid networked haptics stuff
00673     Point3D *what_force_if(Node *n, Point3D *p);
00674         
00675         // Pointer to current GLUI menu, if any
00676         GLUI*   current_attribute_menu;
00677 };
00678 
00679 inline void Object::getBoundingBox(Point3D* min_p, Point3D* max_p)
00680 { nodearray.getBoundingBox(min_p, max_p); }
00681 
00682 inline char* Object::getName()
00683 { return(name); }
00684 
00685 inline char* Object::getPath()
00686 { return(path); }
00687 
00688 inline char* Object::getChildName()
00689 { return(child_name); }
00690 
00691 inline void Object::setName(char* new_name)
00692 { strncpy(name, new_name, NAME_LENGTH); }
00693 
00694 inline void Object::setPath(char* new_path)
00695 { strncpy(path, new_path, PATH_LENGTH); }
00696 
00697 inline void Object::setChildName(char* new_child_name)
00698 { strncpy(child_name, new_child_name, NAME_LENGTH); }
00699 
00700 inline double Object::getTime()
00701 { return(timer.GetElapsedTime()); }
00702 
00703 inline void Object::resetTimer()
00704 { timer.Reset(); }
00705 
00706 inline Object::object_type Object::getType()
00707 { return(type); }
00708 
00709 inline void Object::setType(Object::object_type t)
00710 { type = t; }
00711 
00712 inline ObjectArray* Object::getObjectArray()
00713 { return(objectarray_p); }
00714 
00715 inline double Object::getRadius()
00716 { return(nodearray.getRadius()); }
00717 
00718 inline Point3D Object::getCenter()
00719 { return(nodearray.getCenter()); }
00720 
00721 inline Object::dynamics_type Object::getDynamics()
00722 { return(dynamics); }
00723 
00724 inline void Object::setDynamics(dynamics_type d)
00725 { dynamics = d; }
00726 
00727 inline double Object::getEdgeThresh()
00728 { return(edgethresh); }
00729 
00730 inline Object::behavior_type Object::getBehavior()
00731 { return(behavior); }
00732 
00733 inline void Object::setBehavior(behavior_type b)
00734 { behavior = b; }
00735 
00736 inline Object::numerical_method Object::getNumMethod()
00737 { return(nummethod); }
00738 
00739 inline void Object::setNumMethod(numerical_method n)
00740 { nummethod = n; }
00741 
00742 inline float* Object::getAmbientColor()
00743 { return(mat_ambient); }
00744 
00745 inline float* Object::getDiffuseColor()
00746 { return(mat_diffuse); }
00747 
00748 inline float* Object::getSpecularColor()
00749 { return(mat_specular); }
00750 
00751 inline float* Object::getShininess()
00752 { return(mat_shininess); }
00753 
00754 inline float* Object::getBackAmbientColor()
00755 { return(back_mat_ambient); }
00756 
00757 inline float* Object::getBackDiffuseColor()
00758 { return(back_mat_diffuse); }
00759 
00760 inline float* Object::getBackSpecularColor()
00761 { return(back_mat_specular); }
00762 
00763 inline float* Object::getBackShininess()
00764 { return(back_mat_shininess); }
00765 
00766 inline int Object::isLinked()
00767 { return(sensor_p != NULL); }
00768 
00769 inline Sensor* Object::getSensor()
00770 { return(sensor_p); }
00771 
00772 inline Point3D Object::getSensorOffset()
00773 { return(sensor_offset); }
00774 
00775 inline void Object::setSensorOffset(Point3D offset)
00776 { sensor_offset = offset; }
00777 
00778 inline Point3D Object::getTip()
00779 { return( nodearray.getNode(tip_node)->p ); }
00780 
00781 inline void Object::setTip(int index)
00782 { tip_node = index; }
00783 
00784 inline Point3D Object::getTipDelta()
00785 { return(tipdelta); }
00786 
00787 inline unsigned char* Object::getTexture()
00788 { return(texture); }
00789 
00790 inline void Object::Select()
00791 { selected = 1; }
00792 
00793 inline void Object::Unselect()
00794 { selected = 0; }
00795 
00796 inline void Object::SetVisible(int on)
00797 { visible = on; }
00798 
00799 inline int Object::isVisible()
00800 { return(visible); }
00801 
00802 inline void Object::ForceDisplayUpdate()
00803 { dl_needs_refresh = 1; }
00804 
00805 inline void Object::setLabelOffset(float new_lo)
00806 { label_offset = new_lo; }
00807 
00808 inline Object::collision_extent_type Object::getCollisionExtent()
00809 { return(collision_extent); }
00810 
00811 inline void Object::setCollisionExtent(collision_extent_type extent)
00812 { collision_extent = extent;}
00813 
00814 inline int Object::getNumTotalCollisions()
00815 { return(num_total_collisions); }
00816 
00817 inline void Object::CollisionPairAdd(Collision_pair pair)
00818 { collision_pairs.Append(pair); }
00819 
00820 inline int Object::CollisionPairGetNumElements()
00821 { return collision_pairs.NumElements(); }
00822 
00823 inline Collision_pair Object::CollisionPairGet(int i)
00824 { return collision_pairs[i]; }
00825 
00826 inline BoundingSphereNode* Object::getBoundingSphereRoot()
00827 { return(boundingSphereRoot); }
00828 
00829 inline void Object::setBoundingSphereRoot(BoundingSphereNode* rt)
00830 { boundingSphereRoot = rt; }
00831 
00832 inline int Object::getLinkedPart()
00833 { return(linked_part); }
00834 
00835 inline void Object::setLinkedPart(int lp)
00836 { linked_part = lp; }
00837  
00838 inline DisplayMode Object::getDisplayMode()
00839 { return display_mode; }
00840 
00841 inline void Object::setDisplayMode(DisplayMode dm_in)
00842 { display_mode = dm_in; }
00843 
00844 inline int Object::getGroupNumber()
00845 { return group_number; }
00846 
00847 inline void Object::setGroupNumber(int group)
00848 { group_number = group; }
00849 
00850 inline void Object::Rotate(int axis, double t) 
00851 { 
00852     nodearray.rotate(axis,t);   
00853     nodearray.computeStats(); 
00854     dl_needs_refresh = 1;
00855 }
00856 
00857 inline Face* Object::getLastFace(int f)
00858 {return(last_faces_in_collision[f]);}
00859 
00860 inline int Object::numLastFacesInCollision()
00861 { return(last_faces_in_collision.NumElements()); }
00862 
00863 inline  Face* Object::getCuttingFace(int index)
00864 { return(cutting_faces[index]); }
00865 
00866 inline void Object::setObjectWeight(double w)
00867 { object_weight = w; }
00868 
00869 inline double Object::getObjectWeight()
00870 { return object_weight; }
00871 
00872 inline void Object::setDoDeformOnlyOnGrab(int i)
00873 { do_deform_only_on_grab = i; }
00874 
00875 inline double Object::getHeight() 
00876 { return height; }
00877 
00878 inline void Object::setHeight(double newHeight) 
00879 { height = newHeight; }
00880 
00881 inline RigidHinge* Object::getRigidHinge()
00882 { return rigidHinge; }
00883 
00884 inline void Object::setRigidHinge(RigidHinge* newRigidHinge)
00885 { rigidHinge = newRigidHinge; }
00886 
00887 inline float Object::getRigidHingeAngle() { 
00888   Node* moveHingeNode = getNodeArray()->getNode(rigidHinge->moveHingeNodeIndex);
00889   Node* hingeNode = getNodeArray()->getNode(rigidHinge->hingeNodeIndex);
00890   Point3D currentVector = moveHingeNode->p - hingeNode->p;
00891   currentVector.Normalize();
00892   float currentAngle = rigidHinge->hingeAngleVector.Angle(currentVector);
00893   Point3D currentDirectionNormal = rigidHinge->hingeAngleVector.Cross(currentVector);
00894   currentDirectionNormal.Normalize();
00895   float currentDirectionDotProduct = currentDirectionNormal.Dot(rigidHinge->hingeVector);
00896   if (currentDirectionDotProduct < 0) {
00897     currentAngle = -currentAngle;
00898   }
00899   return currentAngle;
00900 }
00901 
00902 
00903 #endif

Generated on Thu Aug 30 11:03:15 2007 for SPRING Mac by  doxygen 1.5.3