/usr/include/sofa/component/topology/MeshTopology.h is in libsofa1-dev 1.0~beta4-10ubuntu2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 | /******************************************************************************
* SOFA, Simulation Open-Framework Architecture, version 1.0 beta 4 *
* (c) 2006-2009 MGH, INRIA, USTL, UJF, CNRS *
* *
* 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 Street, Fifth Floor, Boston, MA 02110-1301 USA. *
*******************************************************************************
* SOFA :: Modules *
* *
* Authors: The SOFA Team and external contributors (see Authors.txt) *
* *
* Contact information: contact@sofa-framework.org *
******************************************************************************/
#ifndef SOFA_COMPONENT_TOPOLOGY_MESHTOPOLOGY_H
#define SOFA_COMPONENT_TOPOLOGY_MESHTOPOLOGY_H
#include <stdlib.h>
#include <vector>
#include <string>
#include <iostream>
#include <sofa/core/componentmodel/topology/Topology.h>
#include <sofa/core/componentmodel/topology/BaseMeshTopology.h>
#include <sofa/helper/fixed_array.h>
#include <sofa/helper/vector.h>
#include <sofa/component/component.h>
namespace sofa
{
namespace component
{
class MeshLoader;
namespace topology
{
using namespace sofa::defaulttype;
using helper::vector;
using helper::fixed_array;
class SOFA_COMPONENT_CONTAINER_API MeshTopology : public core::componentmodel::topology::BaseMeshTopology
{
public:
MeshTopology();
virtual void parse(core::objectmodel::BaseObjectDescription* arg);
virtual void init();
virtual int getNbPoints() const;
virtual void setNbPoints(int n);
// Complete sequence accessors
virtual const SeqEdges& getEdges();
virtual const SeqTriangles& getTriangles();
virtual const SeqQuads& getQuads();
virtual const SeqTetras& getTetras();
virtual const SeqHexas& getHexas();
// Random accessors
virtual int getNbEdges();
virtual int getNbTriangles();
virtual int getNbQuads();
virtual int getNbTetras();
virtual int getNbHexas();
virtual Edge getEdge(EdgeID i);
virtual Triangle getTriangle(TriangleID i);
virtual Quad getQuad(QuadID i);
virtual Tetra getTetra(TetraID i);
virtual Hexa getHexa(HexaID i);
/// @name neighbors queries
/// @{
/// Returns the set of edges adjacent to a given vertex.
virtual const VertexEdges &getEdgeVertexShell(PointID i);
/// Returns the set of edges adjacent to a given vertex.
virtual const VertexEdges &getOrientedEdgeVertexShell(PointID i);
/// Returns the set of edges adjacent to a given triangle.
virtual const TriangleEdges &getEdgeTriangleShell(TriangleID i);
/// Returns the set of edges adjacent to a given quad.
virtual const QuadEdges &getEdgeQuadShell(QuadID i);
/// Returns the set of edges adjacent to a given tetrahedron.
virtual const TetraEdges& getEdgeTetraShell(TetraID i);
/// Returns the set of edges adjacent to a given hexahedron.
virtual const HexaEdges& getEdgeHexaShell(HexaID i);
/// Returns the set of triangle adjacent to a given vertex.
virtual const VertexTriangles &getTriangleVertexShell(PointID i);
/// Returns the set of oriented triangle adjacent to a given vertex.
virtual const VertexTriangles &getOrientedTriangleVertexShell(PointID i);
/// Returns the set of triangle adjacent to a given edge.
virtual const EdgeTriangles &getTriangleEdgeShell(EdgeID i);
/// Returns the set of triangles adjacent to a given tetrahedron.
virtual const TetraTriangles& getTriangleTetraShell(TetraID i);
/// Returns the set of quad adjacent to a given vertex.
virtual const VertexQuads &getQuadVertexShell(PointID i);
/// Returns the set of oriented quad adjacent to a given vertex.
virtual const VertexQuads &getOrientedQuadVertexShell(PointID i);
/// Returns the set of quad adjacent to a given edge.
virtual const EdgeQuads &getQuadEdgeShell(EdgeID i);
/// Returns the set of quads adjacent to a given hexahedron.
virtual const HexaQuads& getQuadHexaShell(HexaID i);
/// Returns the set of tetrahedra adjacent to a given vertex.
virtual const VertexTetras& getTetraVertexShell(PointID i);
/// Returns the set of tetrahedra adjacent to a given edge.
virtual const EdgeTetras& getTetraEdgeShell(EdgeID i);
/// Returns the set of tetrahedra adjacent to a given triangle.
virtual const TriangleTetras& getTetraTriangleShell(TriangleID i);
/// Returns the set of hexahedra adjacent to a given vertex.
virtual const VertexHexas& getHexaVertexShell(PointID i);
/// Returns the set of hexahedra adjacent to a given edge.
virtual const EdgeHexas& getHexaEdgeShell(EdgeID i);
/// Returns the set of hexahedra adjacent to a given quad.
virtual const QuadHexas& getHexaQuadShell(QuadID i);
/// @}
// Points accessors (not always available)
virtual bool hasPos() const;
virtual double getPX(int i) const;
virtual double getPY(int i) const;
virtual double getPZ(int i) const;
// for procedural creation without file loader
virtual void clear();
void addPoint(double px, double py, double pz);
void addEdge( int a, int b );
void addTriangle( int a, int b, int c );
void addQuad( int a, int b, int c, int d );
void addTetra( int a, int b, int c, int d );
void addHexa( int a, int b, int c, int d, int e, int f, int g, int h );
/// get the current revision of this mesh (use to detect changes)
int getRevision() const { return revision; }
/// return true if the given cube is active, i.e. it contains or is surrounded by mapped points.
/// @deprecated
virtual bool isCubeActive(int /*index*/) { return true; }
void draw();
virtual bool hasVolume() { return ( ( getNbTetras() + getNbHexas() ) > 0 ); }
virtual bool hasSurface() { return ( ( getNbTriangles() + getNbQuads() ) > 0 ); }
virtual bool hasLines() { return ( ( getNbLines() ) > 0 ); }
virtual bool isVolume() { return hasVolume(); }
virtual bool isSurface() { return !hasVolume() && hasSurface(); }
virtual bool isLines() { return !hasVolume() && !hasSurface() && hasLines(); }
// test whether p0p1 has the same orientation as triangle t
// opposite dirction: return -1
// same direction: return 1
// otherwise: return 0
int computeRelativeOrientationInTri(const unsigned int ind_p0, const unsigned int ind_p1, const unsigned int ind_t);
// test whether p0p1 has the same orientation as triangle t
// opposite dirction: return -1
// same direction: return 1
// otherwise: return 0
int computeRelativeOrientationInQuad(const unsigned int ind_p0, const unsigned int ind_p1, const unsigned int ind_q);
protected:
int nbPoints;
Data< vector< defaulttype::Vec<3,SReal> > > seqPoints;
Data<SeqEdges> seqEdges;
bool validEdges;
//SeqTriangles seqTriangles;
Data<SeqTriangles> seqTriangles;
bool validTriangles;
//SeqQuads seqQuads;
Data<SeqQuads> seqQuads;
bool validQuads;
//SeqTetras seqTetras;
Data<SeqTetras> seqTetras;
bool validTetras;
#ifdef SOFA_NEW_HEXA
//SeqHexas seqHexas;
Data<SeqHexas> seqHexas;
#else
Data<SeqCubes> seqHexas;
#endif
bool validHexas;
/** the array that stores the set of edge-vertex shells, ie for each vertex gives the set of adjacent edges */
vector< VertexEdges > m_edgeVertexShell;
/** the array that stores the set of oriented edge-vertex shells, ie for each vertex gives the set of adjacent edges */
vector< VertexEdges > m_orientedEdgeVertexShell;
/** the array that stores the set of edge-triangle shells, ie for each triangle gives the 3 adjacent edges */
vector< TriangleEdges > m_edgeTriangleShell;
/// provides the 4 edges in each quad
vector< QuadEdges > m_edgeQuadShell;
/// provides the set of edges for each tetrahedron
vector< TetraEdges > m_edgeTetraShell;
/// provides the set of edges for each hexahedron
vector< HexaEdges > m_edgeHexaShell;
/// for each vertex provides the set of triangles adjacent to that vertex
vector< VertexTriangles > m_triangleVertexShell;
/// for each vertex provides the set of oriented triangles adjacent to that vertex
vector< VertexTriangles > m_orientedTriangleVertexShell;
/// for each edge provides the set of triangles adjacent to that edge
vector< EdgeTriangles > m_triangleEdgeShell;
/// provides the set of triangles adjacent to each tetrahedron
vector< TetraTriangles > m_triangleTetraShell;
/// for each vertex provides the set of quads adjacent to that vertex
vector< VertexQuads > m_quadVertexShell;
/// for each vertex provides the set of oriented quads adjacent to that vertex
vector< VertexQuads > m_orientedQuadVertexShell;
/// for each edge provides the set of quads adjacent to that edge
vector< EdgeQuads > m_quadEdgeShell;
/// provides the set of quads adjacents to each hexahedron
vector< HexaQuads > m_quadHexaShell;
/// provides the set of tetrahedrons adjacents to each vertex
vector< VertexTetras> m_tetraVertexShell;
/// for each edge provides the set of tetras adjacent to that edge
vector< EdgeTetras > m_tetraEdgeShell;
/// for each triangle provides the set of tetrahedrons adjacent to that triangle
vector< TriangleTetras > m_tetraTriangleShell;
/// provides the set of hexahedrons for each vertex
vector< VertexHexas > m_hexaVertexShell;
/// for each edge provides the set of tetras adjacent to that edge
vector< EdgeHexas > m_hexaEdgeShell;
/// for each quad provides the set of hexahedrons adjacent to that quad
vector< QuadHexas > m_hexaQuadShell;
/** \brief Creates the EdgeSetIndex.
*
* This function is only called if the EdgeVertexShell member is required.
* m_edgeVertexShell[i] contains the indices of all edges having the ith DOF as
* one of their ends.
*/
void createEdgeVertexShellArray();
/** \brief Creates the array of edge indices for each triangle
*
* This function is only called if the EdgeTriangleShell array is required.
* m_edgeTriangleShell[i] contains the 3 indices of the 3 edges opposite to the ith triangle
*/
void createEdgeTriangleShellArray();
/** \brief Creates the array of edge indices for each quad
*
* This function is only called if the EdgeQuadShell array is required.
* m_edgeQuadShell[i] contains the 4 indices of the 4 edges opposite to the ith Quad
*/
void createEdgeQuadShellArray();
/** \brief Creates the array of edge indices for each tetrahedron
*
* This function is only called if the EdgeTetraShell array is required.
* m_edgeTetraShell[i] contains the indices of the edges to the ith tetrahedron
*/
void createEdgeTetraShellArray();
/** \brief Creates the array of edge indices for each hexahedrom
*
* This function is only called if the EdgeHexaShell array is required.
* m_edgeHexaShell[i] contains the indices of the edges to the ith hexahedrom
*/
void createEdgeHexaShellArray();
/** \brief Creates the Triangle Vertex Shell Array
*
* This function is only called if the TriangleVertexShell array is required.
* m_triangleVertexShell[i] contains the indices of all triangles adjacent to the ith vertex
*/
void createTriangleVertexShellArray();
/** \brief Creates the oriented Triangle Vertex Shell Array
*
* This function is only called if the OrientedTriangleVertexShell array is required.
* m_orientedTriangleVertexShell[i] contains the indices of all triangles adjacent to the ith vertex
*/
void createOrientedTriangleVertexShellArray();
/** \brief Creates the Triangle Edge Shell Array
*
* This function is only called if the TriangleEdgeShell array is required.
* m_triangleEdgeShell[i] contains the indices of all triangles adjacent to the ith edge
*/
void createTriangleEdgeShellArray();
/** \brief Creates the array of triangle indices for each tetrahedron
*
* This function is only called if the TriangleTetraShell array is required.
* m_triangleTetraShell[i] contains the indices of the triangles to the ith tetrahedron
*/
void createTriangleTetraShellArray ();
/** \brief Creates the Quad Vertex Shell Array
*
* This function is only called if the QuadVertexShell array is required.
* m_quadVertexShell[i] contains the indices of all quads adjacent to the ith vertex
*/
void createQuadVertexShellArray ();
/** \brief Creates the Quad Vertex Shell Array
*
* This function is only called if the QuadVertexShell array is required.
* m_quadVertexShell[i] contains the indices of all quads adjacent to the ith vertex
*/
void createOrientedQuadVertexShellArray ();
/** \brief Creates the Quad Edge Shell Array
*
* This function is only called if the QuadEdgeShell array is required.
* m_quadEdgeShell[i] contains the indices of all quads adjacent to the ith edge
*/
void createQuadEdgeShellArray();
/** \brief Creates the array of quad indices for each hexahedrom
*
* This function is only called if the QuadHexaShell array is required.
* m_quadHexaShell[i] contains the indices of the quads to the ith hexahedrom
*/
void createQuadHexaShellArray ();
/** \brief Creates the array of tetrahedron indices for each vertex
*
* This function is only called if the TetraVertexShell array is required.
* m_tetraVertexShell[i] contains the indices of the tetras to the ith vertex
*/
void createTetraVertexShellArray ();
/** \brief Creates the array of tetrahedron indices for each edge
*
* This function is only called if the TetraEdgeShell array is required.
* m_tetraEdgeShell[i] contains the indices of the tetrahedrons to the ith edge
*/
void createTetraEdgeShellArray();
/** \brief Creates the array of tetrahedron indices adjacent to each triangle
*
* This function is only called if the TetraTriangleShell array is required.
* m_tetraTriangleShell[i] contains the indices of the tetrahedrons adjacent to the ith triangle
*/
void createTetraTriangleShellArray();
/** \brief Creates the array of hexahedron indices for each vertex
*
* This function is only called if the HexaVertexShell array is required.
* m_hexaVertexShell[i] contains the indices of the hexas to the ith vertex
*/
void createHexaVertexShellArray();
/** \brief Creates the array of hexahedron indices for each edge
*
* This function is only called if the HexaEdgeShell array is required.
* m_hexaEdgeShell[i] contains the indices of the hexahedrons to the ith edge
*/
void createHexaEdgeShellArray ();
/** \brief Creates the array of hexahedron indices adjacent to each quad
*
* This function is only called if the HexaQuadShell array is required.
* m_hexaQuadShell[i] contains the indices of the hexahedrons adjacent to the ith quad
*/
void createHexaQuadShellArray();
/** \brief Returns the Triangle Vertex Shells array.
*
*/
const vector< VertexTriangles > &getTriangleVertexShellArray() ;
/** \brief Returns the Quad Vertex Shells array.
*
*/
const vector< VertexQuads >& getQuadVertexShellArray();
public:
/** \brief Returns the index of the edge joining vertex v1 and vertex v2; returns -1 if no edge exists
*
*/
int getEdgeIndex(PointID v1, PointID v2);
protected:
/** Returns the indices of a triangle given three vertex indices : returns -1 if none */
int getTriangleIndex(PointID v1, PointID v2, PointID v3);
/** \brief Returns the index of the quad joining vertex v1, v2, v3 and v4; returns -1 if no edge exists
*
*/
int getQuadIndex(PointID v1, PointID v2, PointID v3, PointID v4);
/** \brief Returns the index of the tetrahedron given four vertex indices; returns -1 if no edge exists
*
*/
int getTetrahedronIndex(PointID v1, PointID v2, PointID v3, PointID v4);
/** \brief Returns the index of the hexahedron given eight vertex indices; returns -1 if no edge exists
*
*/
int getHexahedronIndex(PointID v1, PointID v2, PointID v3, PointID v4, PointID v5, PointID v6, PointID v7, PointID v8);
/** \brief Returns the index (either 0, 1 ,2 or 3) of the vertex whose global index is vertexIndex. Returns -1 if none
*
*/
int getVertexIndexInTriangle(const Triangle &t, PointID vertexIndex) const;
/** \brief Returns the index (either 0, 1 ,2) of the edge whose global index is edgeIndex. Returns -1 if none
*
*/
int getEdgeIndexInTriangle(const TriangleEdges &t, EdgeID edgeIndex) const;
/** \brief Returns the index (either 0, 1 ,2 or 3) of the vertex whose global index is vertexIndex. Returns -1 if none
*
*/
int getVertexIndexInQuad(Quad &t, PointID vertexIndex) const;
/** \brief Returns the index (either 0, 1 ,2, 3) of the edge whose global index is edgeIndex. Returns -1 if none
*
*/
int getEdgeIndexInQuad(QuadEdges &t, EdgeID edgeIndex) const;
/** \brief Returns the index (either 0, 1 ,2 or 3) of the vertex whose global index is vertexIndex. Returns -1 if none
*
*/
int getVertexIndexInTetrahedron(const Tetra &t, PointID vertexIndex) const;
/** \brief Returns the index (either 0, 1 ,2 ,3, 4, 5) of the edge whose global index is edgeIndex. Returns -1 if none
*
*/
int getEdgeIndexInTetrahedron(const TetraEdges &t, EdgeID edgeIndex) const;
/** \brief Returns the index (either 0, 1 ,2 ,3) of the triangle whose global index is triangleIndex. Returns -1 if none
*
*/
int getTriangleIndexInTetrahedron(const TetraTriangles &t, TriangleID triangleIndex) const;
/** \brief Returns the index (either 0, 1 ,2, 3, 4, 5, 6, or 7) of the vertex whose global index is vertexIndex. Returns -1 if none
*
*/
int getVertexIndexInHexahedron(Hexa &t, PointID vertexIndex) const;
/** \brief Returns the index (either 0, 1 ,2 ,3, 4, 5, 6, 7, 8, 9, 10, 11) of the edge whose global index is edgeIndex. Returns -1 if none
*
*/
int getEdgeIndexInHexahedron(const HexaEdges &t, EdgeID edgeIndex) const;
/** \brief Returns the index (either 0, 1 ,2 ,3, 4, 5) of the quad whose global index is quadIndex. Returns -1 if none
*
*/
int getQuadIndexInHexahedron(const HexaQuads &t, QuadID quadIndex) const;
/** \brief Returns for each index (between 0 and 5) the two vertex indices that are adjacent to that edge
*
*/
Edge getLocalTetrahedronEdges (const unsigned int i) const;
int revision;
Data< bool > _draw;
void invalidate();
virtual void updateEdges();
virtual void updateTriangles();
virtual void updateQuads();
virtual void updateTetras();
virtual void updateHexas();
protected:
virtual void loadFromMeshLoader(sofa::component::MeshLoader* loader);
};
} // namespace topology
} // namespace component
} // namespace sofa
#endif
|