00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include <sofa/core/componentmodel/topology/BaseMeshTopology.h>
00028 #include <sofa/helper/io/MeshTopologyLoader.h>
00029 #include <sofa/helper/system/FileRepository.h>
00030
00031 namespace sofa
00032 {
00033
00034 namespace core
00035 {
00036
00037 namespace componentmodel
00038 {
00039
00040 namespace topology
00041 {
00042
00043 using namespace sofa::defaulttype;
00044 using helper::vector;
00045 using helper::fixed_array;
00046
00047 BaseMeshTopology::BaseMeshTopology()
00048 : d_filename(initData(&d_filename,"filename","Filename of the mesh"))
00049 {
00050 }
00051
00053 const BaseMeshTopology::VertexEdges& BaseMeshTopology::getEdgeVertexShell(PointID)
00054 {
00055 if (getNbEdges()) std::cerr << "WARNING: "<<this->getClassName()<<"::getEdgeVertexShell unsupported."<<std::endl;
00056 static VertexEdges empty;
00057 return empty;
00058 }
00059
00061 const BaseMeshTopology::TriangleEdges& BaseMeshTopology::getEdgeTriangleShell(TriangleID)
00062 {
00063 if (getNbEdges()) std::cerr << "WARNING: "<<this->getClassName()<<"::getEdgeTriangleShell unsupported."<<std::endl;
00064 static TriangleEdges empty;
00065 empty.assign(InvalidID);
00066 return empty;
00067 }
00068
00070 const BaseMeshTopology::QuadEdges& BaseMeshTopology::getEdgeQuadShell(QuadID)
00071 {
00072 if (getNbEdges()) std::cerr << "WARNING: "<<this->getClassName()<<"::getEdgeQuadShell unsupported."<<std::endl;
00073 static QuadEdges empty;
00074 empty.assign(InvalidID);
00075 return empty;
00076 }
00077
00079 const BaseMeshTopology::TetraEdges& BaseMeshTopology::getEdgeTetraShell(TetraID)
00080 {
00081 if (getNbEdges()) std::cerr << "WARNING: "<<this->getClassName()<<"::getEdgeTetraShell unsupported."<<std::endl;
00082 static TetraEdges empty;
00083 empty.assign(InvalidID);
00084 return empty;
00085 }
00086
00087
00089 const BaseMeshTopology::HexaEdges& BaseMeshTopology::getEdgeHexaShell(HexaID)
00090 {
00091 if (getNbEdges()) std::cerr << "WARNING: "<<this->getClassName()<<"::getEdgeHexaShell unsupported."<<std::endl;
00092 static HexaEdges empty;
00093 empty.assign(InvalidID);
00094 return empty;
00095 }
00096
00098 const BaseMeshTopology::VertexTriangles& BaseMeshTopology::getTriangleVertexShell(PointID)
00099 {
00100 if (getNbTriangles()) std::cerr << "WARNING: "<<this->getClassName()<<"::getTriangleVertexShell unsupported."<<std::endl;
00101 static VertexTriangles empty;
00102 return empty;
00103 }
00104
00106 const BaseMeshTopology::EdgeTriangles& BaseMeshTopology::getTriangleEdgeShell(EdgeID)
00107 {
00108 if (getNbTriangles()) std::cerr << "WARNING: "<<this->getClassName()<<"::getEdgeVertexShell unsupported."<<std::endl;
00109 static EdgeTriangles empty;
00110 return empty;
00111 }
00112
00114 const BaseMeshTopology::TetraTriangles& BaseMeshTopology::getTriangleTetraShell(TetraID)
00115 {
00116 if (getNbTriangles()) std::cerr << "WARNING: "<<this->getClassName()<<"::getTriangleTetraShell unsupported."<<std::endl;
00117 static TetraTriangles empty;
00118 empty.assign(InvalidID);
00119 return empty;
00120 }
00121
00123 const BaseMeshTopology::VertexQuads& BaseMeshTopology::getQuadVertexShell(PointID)
00124 {
00125 if (getNbQuads()) std::cerr << "WARNING: "<<this->getClassName()<<"::getQuadVertexShell unsupported."<<std::endl;
00126 static VertexQuads empty;
00127 return empty;
00128 }
00129
00131 const BaseMeshTopology::EdgeQuads& BaseMeshTopology::getQuadEdgeShell(EdgeID)
00132 {
00133 if (getNbQuads()) std::cerr << "WARNING: "<<this->getClassName()<<"::getQuadEdgeShell unsupported."<<std::endl;
00134 static EdgeQuads empty;
00135 return empty;
00136 }
00137
00139 const BaseMeshTopology::HexaQuads& BaseMeshTopology::getQuadHexaShell(HexaID)
00140 {
00141 if (getNbQuads()) std::cerr << "WARNING: "<<this->getClassName()<<"::getQuadHexaShell unsupported."<<std::endl;
00142 static HexaQuads empty;
00143 empty.assign(InvalidID);
00144 return empty;
00145 }
00146
00148 const BaseMeshTopology::VertexTetras& BaseMeshTopology::getTetraVertexShell(PointID)
00149 {
00150 if (getNbTetras()) std::cerr << "WARNING: "<<this->getClassName()<<"::getTetraVertexShell unsupported."<<std::endl;
00151 static VertexTetras empty;
00152 return empty;
00153 }
00154
00156 const BaseMeshTopology::EdgeTetras& BaseMeshTopology::getTetraEdgeShell(EdgeID)
00157 {
00158 if (getNbTetras()) std::cerr << "WARNING: "<<this->getClassName()<<"::getTetraEdgeShell unsupported."<<std::endl;
00159 static EdgeTetras empty;
00160 return empty;
00161 }
00162
00164 const BaseMeshTopology::TriangleTetras& BaseMeshTopology::getTetraTriangleShell(TriangleID)
00165 {
00166 if (getNbTetras()) std::cerr << "WARNING: "<<this->getClassName()<<"::getTetraTriangleShell unsupported."<<std::endl;
00167 static TriangleTetras empty;
00168 return empty;
00169 }
00170
00172 const BaseMeshTopology::VertexHexas& BaseMeshTopology::getHexaVertexShell(PointID)
00173 {
00174 if (getNbHexas()) std::cerr << "WARNING: "<<this->getClassName()<<"::getHexaVertexShell unsupported."<<std::endl;
00175 static VertexHexas empty;
00176 return empty;
00177 }
00178
00180 const BaseMeshTopology::EdgeHexas& BaseMeshTopology::getHexaEdgeShell(EdgeID)
00181 {
00182 if (getNbHexas()) std::cerr << "WARNING: "<<this->getClassName()<<"::getHexaEdgeShell unsupported."<<std::endl;
00183 static EdgeHexas empty;
00184 return empty;
00185 }
00186
00188 const BaseMeshTopology::QuadHexas& BaseMeshTopology::getHexaQuadShell(QuadID)
00189 {
00190 if (getNbHexas()) std::cerr << "WARNING: "<<this->getClassName()<<"::getHexaQuadShell unsupported."<<std::endl;
00191 static QuadHexas empty;
00192 return empty;
00193 }
00194
00195 void BaseMeshTopology::parse(core::objectmodel::BaseObjectDescription* arg)
00196 {
00197 if (arg->getAttribute("filename"))
00198 {
00199 d_filename.setValue( arg->getAttribute("filename") );
00200 this->load(arg->getAttribute("filename"));
00201 }
00202 arg->removeAttribute("filename");
00203 this->core::componentmodel::topology::Topology::parse(arg);
00204 }
00205
00206 class DefaultMeshTopologyLoader : public helper::io::MeshTopologyLoader
00207 {
00208 public:
00209 BaseMeshTopology* dest;
00210 DefaultMeshTopologyLoader(BaseMeshTopology* dest) : dest(dest) {}
00211 virtual void addPoint(double px, double py, double pz)
00212 {
00213 dest->addPoint(px,py,pz);
00214 }
00215 virtual void addLine(int p1, int p2)
00216 {
00217 dest->addEdge(p1,p2);
00218 }
00219 virtual void addTriangle(int p1, int p2, int p3)
00220 {
00221 dest->addTriangle(p1,p2,p3);
00222 }
00223 virtual void addQuad(int p1, int p2, int p3, int p4)
00224 {
00225 dest->addQuad(p1,p2,p3,p4);
00226 }
00227 virtual void addTetra(int p1, int p2, int p3, int p4)
00228 {
00229 dest->addTetra(p1,p2,p3,p4);
00230 }
00231 virtual void addCube(int p1, int p2, int p3, int p4, int p5, int p6, int p7, int p8)
00232 {
00233 dest->addHexa(p1,p2,p3,p4,p5,p6,p7,p8);
00234 }
00235 };
00236
00237 bool BaseMeshTopology::load(const char* filename)
00238 {
00239 clear();
00240 std::string meshFilename(filename);
00241 if (!sofa::helper::system::DataRepository.findFile (meshFilename))
00242 {
00243 logWarning(std::string("Mesh \"") + filename +std::string("\" not found"));
00244 return false;
00245 }
00246 this->d_filename.setValue( meshFilename );
00247 DefaultMeshTopologyLoader loader(this);
00248 if (!loader.load(meshFilename.c_str()))
00249 {
00250 logWarning(std::string("Unable to load Mesh \"") + filename );
00251 return false;
00252 }
00253 return true;
00254 }
00255
00256
00257 void BaseMeshTopology::clear()
00258 {
00259 std::cerr << "WARNING: "<<this->getClassName()<<"::clear() not supported." << std::endl;
00260 }
00261
00262 void BaseMeshTopology::addPoint(double, double, double)
00263 {
00264 std::cerr << "WARNING: "<<this->getClassName()<<"::addPoint() not supported." << std::endl;
00265 }
00266
00267 void BaseMeshTopology::addEdge(int, int)
00268 {
00269 std::cerr << "WARNING: "<<this->getClassName()<<"::addEdge() not supported." << std::endl;
00270 }
00271
00272 void BaseMeshTopology::addTriangle(int, int, int)
00273 {
00274 std::cerr << "WARNING: "<<this->getClassName()<<"::addTriangle() not supported." << std::endl;
00275 }
00276
00277 void BaseMeshTopology::addQuad(int, int, int, int)
00278 {
00279 std::cerr << "WARNING: "<<this->getClassName()<<"::addQuad() not supported." << std::endl;
00280 }
00281
00282 void BaseMeshTopology::addTetra(int, int, int, int)
00283 {
00284 std::cerr << "WARNING: "<<this->getClassName()<<"::addTetra() not supported." << std::endl;
00285 }
00286
00287 void BaseMeshTopology::addHexa(int, int, int, int, int, int, int, int)
00288 {
00289 std::cerr << "WARNING: "<<this->getClassName()<<"::addHexa() not supported." << std::endl;
00290 }
00291
00292 std::list<const TopologyChange *>::const_iterator BaseMeshTopology::firstChange() const
00293 {
00294 std::cerr << "WARNING: "<<this->getClassName()<<"::firstChange() not supported." << std::endl;
00295 std::list<const TopologyChange *>::const_iterator l;
00296 return l;
00297 }
00298
00299 std::list<const TopologyChange *>::const_iterator BaseMeshTopology::lastChange() const
00300 {
00301 std::cerr << "WARNING: "<<this->getClassName()<<"::lastChange() not supported." << std::endl;
00302 std::list<const TopologyChange *>::const_iterator l;
00303 return l;
00304 }
00305
00306 std::list<const TopologyChange *>::const_iterator BaseMeshTopology::firstStateChange() const
00307 {
00308 std::cerr << "WARNING: "<<this->getClassName()<<"::firstStateChange() not supported." << std::endl;
00309 std::list<const TopologyChange *>::const_iterator l;
00310 return l;
00311 }
00312
00313 std::list<const TopologyChange *>::const_iterator BaseMeshTopology::lastStateChange() const
00314 {
00315 std::cerr << "WARNING: "<<this->getClassName()<<"::lastStateChange() not supported." << std::endl;
00316 std::list<const TopologyChange *>::const_iterator l;
00317 return l;
00318 }
00319
00320 int BaseMeshTopology::getEdgeIndex(PointID, PointID)
00321 {
00322 std::cerr << "WARNING: "<<this->getClassName()<<"::getEdgeIndex() not supported." << std::endl;
00323 return 0;
00324 }
00325
00326 int BaseMeshTopology::getTriangleIndex(PointID, PointID, PointID)
00327 {
00328 std::cerr << "WARNING: "<<this->getClassName()<<"::getTriangleIndex() not supported." << std::endl;
00329 return 0;
00330 }
00331
00332 int BaseMeshTopology::getQuadIndex(PointID, PointID, PointID, PointID)
00333 {
00334 std::cerr << "WARNING: "<<this->getClassName()<<"::getQuadIndex() not supported." << std::endl;
00335 return 0;
00336 }
00337
00338 int BaseMeshTopology::getTetrahedronIndex(PointID, PointID, PointID, PointID)
00339 {
00340 std::cerr << "WARNING: "<<this->getClassName()<<"::getTetrahedronIndex() not supported." << std::endl;
00341 return 0;
00342 }
00343
00344 int BaseMeshTopology::getHexahedronIndex(PointID, PointID, PointID, PointID, PointID, PointID, PointID, PointID)
00345 {
00346 std::cerr << "WARNING: "<<this->getClassName()<<"::getHexahedronIndex() not supported." << std::endl;
00347 return 0;
00348 }
00349
00350 int BaseMeshTopology::getVertexIndexInTriangle(const Triangle &, PointID) const
00351 {
00352 std::cerr << "WARNING: "<<this->getClassName()<<"::getVertexIndexInTriangle() not supported." << std::endl;
00353 return 0;
00354 }
00355
00356 int BaseMeshTopology::getEdgeIndexInTriangle(const TriangleEdges &, EdgeID) const
00357 {
00358 std::cerr << "WARNING: "<<this->getClassName()<<"::getEdgeIndexInTriangle() not supported." << std::endl;
00359 return 0;
00360 }
00361
00362 int BaseMeshTopology::getVertexIndexInQuad(Quad &, PointID) const
00363 {
00364 std::cerr << "WARNING: "<<this->getClassName()<<"::getVertexIndexInQuad() not supported." << std::endl;
00365 return 0;
00366 }
00367
00368 int BaseMeshTopology::getEdgeIndexInQuad(QuadEdges &, EdgeID) const
00369 {
00370 std::cerr << "WARNING: "<<this->getClassName()<<"::getEdgeIndexInQuad() not supported." << std::endl;
00371 return 0;
00372 }
00373
00374 int BaseMeshTopology::getVertexIndexInTetrahedron(const Tetra &, PointID) const
00375 {
00376 std::cerr << "WARNING: "<<this->getClassName()<<"::getVertexIndexInTetrahedron() not supported." << std::endl;
00377 return 0;
00378 }
00379
00380 int BaseMeshTopology::getEdgeIndexInTetrahedron(const TetraEdges &, EdgeID) const
00381 {
00382 std::cerr << "WARNING: "<<this->getClassName()<<"::getEdgeIndexInTetrahedron() not supported." << std::endl;
00383 return 0;
00384 }
00385
00386 int BaseMeshTopology::getTriangleIndexInTetrahedron(const TetraTriangles &, TriangleID) const
00387 {
00388 std::cerr << "WARNING: "<<this->getClassName()<<"::getTriangleIndexInTetrahedron() not supported." << std::endl;
00389 return 0;
00390 }
00391
00392 int BaseMeshTopology::getVertexIndexInHexahedron(Hexa &, PointID) const
00393 {
00394 std::cerr << "WARNING: "<<this->getClassName()<<"::getVertexIndexInHexahedron() not supported." << std::endl;
00395 return 0;
00396 }
00397
00398 int BaseMeshTopology::getEdgeIndexInHexahedron(const HexaEdges &, EdgeID) const
00399 {
00400 std::cerr << "WARNING: "<<this->getClassName()<<"::getEdgeIndexInHexahedron() not supported." << std::endl;
00401 return 0;
00402 }
00403
00404 int BaseMeshTopology::getQuadIndexInHexahedron(const HexaQuads &, QuadID) const
00405 {
00406 std::cerr << "WARNING: "<<this->getClassName()<<"::getQuadIndexInHexahedron() not supported." << std::endl;
00407 return 0;
00408 }
00409
00410 BaseMeshTopology::Edge BaseMeshTopology::getLocalTetrahedronEdges (const unsigned int) const
00411 {
00412 static BaseMeshTopology::Edge empty;
00413 std::cerr << "WARNING: "<<this->getClassName()<<"::getLocalTetrahedronEdges() not supported." << std::endl;
00414 return empty;
00415 }
00416
00417 }
00418
00419 }
00420
00421 }
00422
00423 }