/* ****************************************************************************** * Title: ColDetection * Project: ColDetection Library ****************************************************************************** * File: ColDetection.h * Author: Romain Rodriguez * Created: 2003-01-06 * Last update: 2003-05-20 ****************************************************************************** * Description: * ColDetection header ****************************************************************************** * Copyright (c) 2003, INRIA CYBERMOVE * * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ****************************************************************************** */ #ifndef __vtkColDetection_h #define __vtkColDetection_h // Comment this if you don't want to have some debug informations #undef DEBUG #define DEBUG #ifdef _WIN32 #include #else #include #endif #include "tools.h" //pendiente #include "Matrix4f.h" //no se convierte solo definicion de tipo #include "vtkDObject.h"//modificado #include "vtkBoundingBoxBinTree.h"//hecho #include "vtkMeshCol.h"//hecho #include "vtkEnGJK.h"//hecho #include "vtkConcaveDistance.h"//hecho #include "vtkDeformableMeshCol.h"//hecho #include "vtkObject.h" #include "Macros.h" #include "vtkesquiColDetectWin32Header.h" //BTX //#include "stdafx.h" //! Estructura de datos que se se emplea en la detección de colisiones struct CDPrivate { public: //! Vector de los objetos que se va a estudiar su colisión std::vector* vectorOfCDObjects; //! Vector de distancias utilizando el algortimo GJK. std::vector* vectorOfEnGJK; //! Vector de las distancias para objetos concavos std::vector* vectorOfConcaveDistance; //! Vector de colisiones entre modelos std::vector* vectorOfMeshCol; //! vector de colisiones entre modelos deformables std::vector* vectorOfDeformableMeshCol; }; typedef struct{ std::vector normal; }tipoNormal; //ETX //! Class for collision detection class VTK_ESQUI_COLDETECT_EXPORT vtkColDetection //: public vtkObject { public: static vtkColDetection *New() {return new vtkColDetection;}; const char *GetClassName() {return "vtkColDetection";}; //! Constructor vtkColDetection(void); //! Destructor ~vtkColDetection(void); // ========================================================================== //! Objects Definition //! Create a new object whith the identifier id. //BTX unsigned createObject(); //ETX //! Begin of the construction of the geometry of the object id /*! The Object id has nbFacets facets and nbVertices vertices Funcion para reopresentar los modelos dentro de la libreria. En este caso le das el nmero de caras que tiene la malla (son triangulares) y el nmero de vertices */ void beginObject(unsigned id, unsigned nbFacets, unsigned nbVertices); //! Set the table of vertices /*! Ith vertex = (vertex.x , vertex.y , vertex.z ) vertices[i] = (vertices[i][0], vertices[i][1], vertices[i][2]) Sam: le das la informaci� de la geometr� de los modelos */ void setVertices(unsigned id, double** vertices); //! Set the table of vertices /*! Ith vertex = (vertex.x , vertex.y , vertex.z ) vertices[i] = (v1.x, v1.y, v1.z, v2.x, v2.y, v2.z) Modificacion para optimizar la utilizacion de la libreria pasando directamente un vector que es como se utiliza tanto en nuestro simulador como en el objeto CDObject */ void setVertices(unsigned id, double* vertices); //BTX //! Returns verts of facet void getVertices(unsigned id, unsigned face, unsigned* vertices); //ETX //! Retruns the coords of a vert void coordVertices(unsigned id, unsigned vertex, float* coord); //! Returns relative coords of a vert void coordVerticesRelativas(unsigned id, unsigned vertex, float* coord); //! Add a triangle to the object id /*! This triangle is the idFace triangle and componed of the vertices v1, v2, v3 */ //Sam: le das la informaci� topol�ica de los modelos, debemos saber el indetificador del la cara // y el identificadro de cada uno de los v�tices. void addTriangle(unsigned id, unsigned idFace, const unsigned v1, const unsigned v2, const unsigned v3); //! End of the construction of the geometry of the object id // Sam: Cuando finalices de defunir un modelo debes ejecutar esta funci�. void endObject(unsigned id); // ========================================================================== //! Set the transformation matrix of the object /*! 4x4 matrices Transformation matrix is in column major order and used to multiply column vector on the left as in OpenGL (ie v' = M.v). Coordinate system and rotations are assumed to be right-handed. x y z w x y z w --------------- --------------- x | 0 4 8 12 x | r.s r.s r.s t y | 1 5 9 13 y | r.s r.s r.s t (for affine transformations) z | 2 6 10 14 z | r.s r.s r.s t w | 3 7 11 15 w | 0 0 0 1 element (i,j) (raw i, column j) of matrix M is accessed by M[4*j+i] The second figure is for transformation matrices. It implies that M = T.R.S, i.e scaling is applied first, then rotation and last translation. */ void setTransformationMatrix(unsigned id, double* trans[16]); // ========================================================================== // Operation on objects // ========================================================================== //! Computing Distance between Convex Objects /*! Compute the distance between the convex objects id1 and id2 Return the identifier of the interaction between the two objects */ // Sam: el par�etro de salida es un identificador de la interacci�.Este identificador // es el empleado para calcular la distancia exacta mediante la funci� getDistanceConvex y la // funci� de obtener los puntos de cada objeto que tienen la disancia m�ima. Supongo que // xA,xB y xC son las coordenadas de los puntos del objeto id1 y xB,yB y zB es son las coordenadas // del punto de id2 m� cercano a id1. //BTX unsigned distanceConvex(unsigned id1, unsigned id2); //ETX //! Get the distance between the two convex of distanceConvex id is the identifier of the interaction double getDistanceConvex(unsigned id); //! Get the coordinates of the points that realize the distance between the 2 convex objects /*! \param id Is the identifier of the interaction */ void getPointDistanceConvex(unsigned id, double& xA, double& yA, double& zA, double& xB, double& yB, double& zB); // ========================================================================== //! Computing Distance between Convex Objects /*! Compute the distance between the concave objects id1 and id2 Return the identifier of the interaction between the two objects */ //BTX unsigned distanceConcave(unsigned id1, unsigned id2); //ETX //! Get the distance between the two concave of distanceConcave /*! \param id is the identifier of the interaction */ double getDistanceConcave(unsigned id); //! Get the coordinates of the points that realize the distance between the 2 convex objects /*! \param id is the identifier of the interaction */ void getPointDistanceConcave(unsigned id, double& xA, double& yA, double& zA, double& xB, double& yB, double& zB); // ========================================================================== //! Collision Detection between 2 objects /* Perform the collision detection the objects id1 and id2 Return the identifier of the interaction between the two objects Set search to true if you want to search for the contact surface */ //BTX unsigned collide(unsigned id1, unsigned id2, bool search); //ETX //! Verify the collision between the objects of collide(...) /*! \param Id is the identifier of the interaction */ bool verifyCollision(unsigned id); //! Report the results of collision detection /*! To have these informations you have to set search to true \param Id is the identifier of the interaction \param contactSurface is a vector of index of facets in the contact surface */ //BTX void reportCollision(unsigned id, std::vector& contactSurfaceObject1, std::vector& contactSurfaceObject2, std::vector& normalObject1, std::vector& normalObject2); //ETX // ========================================================================== // Collision Detection between 2 deformable objects //! Update the coordinates of the vertex idVertex of the object id void updateVertex(unsigned id, unsigned idVertex, double x, double y, double z); //! Perform the collision detection the deformable objects id1 and id2 /*! Return the identifier of the interaction between the two objects Set search to true if you want to search for the contact surface */ //BTX unsigned collideDeformable(unsigned id1, unsigned id2, bool search); //ETX void createBoundingBoxTree(unsigned id); //! Verify the collision between the deformable objects of collide(...) /*! \param Id is the identifier of the interaction */ bool verifyCollisionDeformable(unsigned id); //! Report the results of collision detection between the deformable objects. /*! To have these informations you have to set search to true \param Id is the identifier of the interaction \param contactSurface is a vector of index of facets in the contact surface */ //BTX void reportCollisionDeformable(unsigned id, std::vector& contactSurfaceObject1, std::vector& contactSurfaceObject2); // ========================================================================== // Debug and Render Tools //! Get the list of vertices of the bounding box tree for the object /*! \param id Each element of listVertices constains the 24 float that represent each vertex of each bounding box. */ void getBoundingBoxVertex(unsigned id, std::vector& listVertices); //ETX virtual double* ObtenerMatriz(unsigned id){ return NULL; }; protected: CDPrivate* cdPrivate; private: bool Debug; vtkColDetection(const vtkColDetection &); void operator =(const vtkColDetection &); }; #endif /* ifndef COLDETECTION_H */ /* ColDetection.h ends here */