| 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 |
#ifndef _OBJMESH_H_ |
| 31 |
#define _OBJMESH_H_ |
| 32 |
|
| 33 |
#include <math.h> |
| 34 |
#include <string> |
| 35 |
#include <vector> |
| 36 |
#include <list> |
| 37 |
#include <map> |
| 38 |
#include <iostream> |
| 39 |
#include <algorithm> |
| 40 |
#include <assert.h> |
| 41 |
#include <exception> |
| 42 |
#include "minivector.h" |
| 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 |
class ObjMeshException : public std::exception |
| 76 |
{ |
| 77 |
public: |
| 78 |
ObjMeshException(const std::string & reason); |
| 79 |
ObjMeshException(const std::string & reason, const std::string & filename, unsigned int line); |
| 80 |
virtual ~ObjMeshException() throw() {} |
| 81 |
const std::string & getReason() const throw() { return reason; } |
| 82 |
virtual const char * what() const throw() { return reason.c_str(); } |
| 83 |
|
| 84 |
protected: |
| 85 |
std::string reason; |
| 86 |
}; |
| 87 |
|
| 88 |
class ObjMesh |
| 89 |
{ |
| 90 |
public: |
| 91 |
|
| 92 |
typedef enum {ASCII, BINARY, NUM_FILE_FORMATS} fileFormatType; |
| 93 |
typedef enum {FILE_STREAM, MEMORY_STREAM} streamType; |
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
class Vertex |
| 98 |
{ |
| 99 |
public: |
| 100 |
explicit Vertex(const unsigned int & positionIndex_) |
| 101 |
: positionIndex(positionIndex_), textureIndex(std::make_pair(false, 0)), normalIndex(std::make_pair(false, 0)) {} |
| 102 |
|
| 103 |
explicit Vertex(const unsigned int & positionIndex_, const unsigned int & textureIndex_) |
| 104 |
: positionIndex(positionIndex_), textureIndex(std::make_pair(true, textureIndex_)), normalIndex(std::make_pair(false, 0)) {} |
| 105 |
|
| 106 |
explicit Vertex(const unsigned int & positionIndex_, const unsigned int & textureIndex_, const unsigned int & normalIndex_) |
| 107 |
: positionIndex(positionIndex_), textureIndex(std::make_pair(true, textureIndex_)), normalIndex(std::make_pair(true, normalIndex_)) {} |
| 108 |
|
| 109 |
explicit Vertex(const unsigned int & positionIndex_, const std::pair<bool, unsigned int> textureIndex_, const std::pair<bool, unsigned int> normalIndex_) |
| 110 |
: positionIndex(positionIndex_), textureIndex(textureIndex_), normalIndex(normalIndex_) {} |
| 111 |
|
| 112 |
inline unsigned int getPositionIndex() const { return positionIndex; } |
| 113 |
inline unsigned int getNormalIndex() const { assert(normalIndex.first); return normalIndex.second; } |
| 114 |
inline unsigned int getTextureCoordinateIndex() const { assert(textureIndex.first); return textureIndex.second; } |
| 115 |
inline std::pair< bool, unsigned int > getTextureIndexPair() const { return textureIndex; } |
| 116 |
inline std::pair< bool, unsigned int > getNormalIndexPair() const { return normalIndex; } |
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
inline bool hasNormalIndex() const { return normalIndex.first; } |
| 121 |
inline bool hasTextureCoordinateIndex() const { return textureIndex.first; } |
| 122 |
|
| 123 |
inline void setPositionIndex(unsigned int positionIndex_) { positionIndex = positionIndex_; } |
| 124 |
inline void setNormalIndex(unsigned int normalIndex_) { normalIndex = std::pair<bool,unsigned int>(true, normalIndex_); } |
| 125 |
inline void setTextureCoordinateIndex(unsigned int textureCoordinate_) { textureIndex = std::pair<bool,unsigned int>(true, textureCoordinate_); } |
| 126 |
|
| 127 |
protected: |
| 128 |
unsigned int positionIndex; |
| 129 |
std::pair< bool, unsigned int > textureIndex; |
| 130 |
std::pair< bool, unsigned int > normalIndex; |
| 131 |
}; |
| 132 |
|
| 133 |
class Material |
| 134 |
{ |
| 135 |
public: |
| 136 |
explicit Material(const std::string name_, const Vec3d & Ka_, const Vec3d & Kd_, const Vec3d & Ks_, double shininess_=0, const std::string textureFilename_=std::string()): |
| 137 |
Ka(Ka_), Kd(Kd_), Ks(Ks_), shininess(shininess_), alpha(1.0), name(name_), textureFilename(textureFilename_) {} |
| 138 |
|
| 139 |
explicit Material(): Ka(Vec3d(1,1,1)), Kd(Vec3d(1,1,1)), Ks(Vec3d(1,1,1)), shininess(0), alpha(1.0), name(std::string("default")), textureFilename(std::string()) {} |
| 140 |
|
| 141 |
inline std::string getName() const { return name; } |
| 142 |
inline const Vec3d & getKa() const { return Ka; } |
| 143 |
inline const Vec3d & getKd() const { return Kd; } |
| 144 |
inline const Vec3d & getKs() const { return Ks; } |
| 145 |
inline double getShininess() const { return shininess; } |
| 146 |
inline double getAlpha() const { return alpha; } |
| 147 |
|
| 148 |
inline void setName(const std::string & name_) { name = name_; } |
| 149 |
inline void setKa(const Vec3d & Ka_) { Ka = Ka_; } |
| 150 |
inline void setKd(const Vec3d & Kd_) { Kd = Kd_; } |
| 151 |
inline void setKs(const Vec3d & Ks_) { Ks = Ks_; } |
| 152 |
inline void setShininess(double shininess_) { shininess = shininess_; } |
| 153 |
inline void setAlpha(double alpha_) { alpha = alpha_; } |
| 154 |
inline void setTextureFilename(const std::string & textureFilename_) { textureFilename = textureFilename_; } |
| 155 |
inline void setTextureFilename(const char * textureFilename_) { textureFilename = std::string(textureFilename_); } |
| 156 |
|
| 157 |
inline bool hasTextureFilename() const { return (textureFilename.size() > 0); } |
| 158 |
inline std::string getTextureFilename() const { return textureFilename; } |
| 159 |
|
| 160 |
bool operator==(const Material & material2) const; |
| 161 |
|
| 162 |
protected: |
| 163 |
Vec3d Ka, Kd, Ks; |
| 164 |
double shininess; |
| 165 |
double alpha; |
| 166 |
std::string name; |
| 167 |
std::string textureFilename; |
| 168 |
}; |
| 169 |
|
| 170 |
class Face |
| 171 |
{ |
| 172 |
public: |
| 173 |
explicit Face() : faceNormal(std::make_pair(false, Vec3d())) { vertices.reserve(3); } |
| 174 |
explicit Face(const Vertex & v1, const Vertex & v2, const Vertex & v3) : faceNormal(std::make_pair(false, Vec3d())) |
| 175 |
{ |
| 176 |
vertices.reserve(3); |
| 177 |
vertices.push_back(v1); |
| 178 |
vertices.push_back(v2); |
| 179 |
vertices.push_back(v3); |
| 180 |
} |
| 181 |
|
| 182 |
inline size_t getNumVertices() const { return vertices.size(); } |
| 183 |
|
| 184 |
inline const Vertex & getVertex(unsigned int vertex) const { return vertices[vertex]; } |
| 185 |
inline const Vertex * getVertexHandle(unsigned int vertex) const { return &(vertices[vertex]); } |
| 186 |
|
| 187 |
inline void setFaceNormal(const Vec3d & normal) { faceNormal = std::pair<bool, Vec3d>(true, normal); } |
| 188 |
inline bool hasFaceNormal() const { return faceNormal.first; }; |
| 189 |
inline const Vec3d & getFaceNormal() const { assert(faceNormal.first); return faceNormal.second; } |
| 190 |
|
| 191 |
inline void addVertex(const Vertex & v) { vertices.push_back(v); } |
| 192 |
inline void removeVertex(unsigned int i) { vertices.erase(vertices.begin() + i); } |
| 193 |
inline void reverseVertices() { reverse(vertices.begin(), vertices.end()); } |
| 194 |
inline void printVertices() const { for(unsigned int i=0; i<vertices.size(); i++) std::cout << vertices[i].getPositionIndex() << " "; } |
| 195 |
|
| 196 |
protected: |
| 197 |
std::vector< Vertex > vertices; |
| 198 |
std::pair< bool, Vec3d > faceNormal; |
| 199 |
}; |
| 200 |
|
| 201 |
class Group |
| 202 |
{ |
| 203 |
public: |
| 204 |
explicit Group(const std::string & name_, unsigned int materialIndex_=0) |
| 205 |
: name(name_), materialIndex(materialIndex_) {} |
| 206 |
|
| 207 |
inline size_t getNumFaces() const { return faces.size(); } |
| 208 |
|
| 209 |
inline const Face & getFace(unsigned int face) const { return faces[face]; } |
| 210 |
inline const Face * getFaceHandle(unsigned int face) const { return &(faces[face]); } |
| 211 |
inline Face * getFaceHandle(unsigned int face) { return &(faces[face]); } |
| 212 |
inline const std::string & getName() const { return name; } |
| 213 |
void setName(const std::string & name_) { name = name_; } |
| 214 |
inline unsigned int getMaterialIndex() const { return materialIndex; } |
| 215 |
inline void setMaterialIndex(unsigned int materialIndex_) { materialIndex = materialIndex_; } |
| 216 |
|
| 217 |
inline void addFace(const Face & face) { faces.push_back(face); } |
| 218 |
inline void reverseFace(unsigned int face) { faces[face].reverseVertices(); } |
| 219 |
void removeFace(unsigned int face); |
| 220 |
|
| 221 |
protected: |
| 222 |
std::string name; |
| 223 |
unsigned int materialIndex; |
| 224 |
std::vector< Face > faces; |
| 225 |
}; |
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
explicit ObjMesh(const std::string & filename, fileFormatType fileFormat = ASCII, int verbose = 0); |
| 231 |
|
| 232 |
|
| 233 |
explicit ObjMesh() {} |
| 234 |
|
| 235 |
|
| 236 |
explicit ObjMesh(int numVertices, const double * vertices, int numTriangles, const int * triangles); |
| 237 |
|
| 238 |
|
| 239 |
explicit ObjMesh(int numVertices, const double * vertices, int numFaces, const int* faceVertexCounts, const int * faces); |
| 240 |
|
| 241 |
|
| 242 |
explicit ObjMesh(const ObjMesh & objMesh); |
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
explicit ObjMesh(void * binaryInputStream, streamType stream, int verbose = 0); |
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
inline size_t getNumVertices() const { return vertexPositions.size(); } |
| 251 |
unsigned int getNumFaces() const; |
| 252 |
inline size_t getNumNormals() const { return normals.size(); } |
| 253 |
inline size_t getNumTextureCoordinates() const { return textureCoordinates.size(); } |
| 254 |
inline size_t getNumGroups() const { return groups.size(); } |
| 255 |
inline size_t getNumMaterials() const { return materials.size(); } |
| 256 |
|
| 257 |
std::vector<std::string> getGroupNames() const; |
| 258 |
|
| 259 |
inline const std::string & getFilename() const { return filename; } |
| 260 |
|
| 261 |
|
| 262 |
void printInfo() const; |
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
inline int getVertexIndex(unsigned int group, unsigned int face, unsigned int vertex) const { return groups[group].getFace(face).getVertex(vertex).getPositionIndex(); } |
| 268 |
|
| 269 |
inline const Vec3d & getPosition(int vertexIndex) const { return vertexPositions[vertexIndex]; } |
| 270 |
inline const Vec3d & getPosition(const Vertex & vertex) const { return vertexPositions[vertex.getPositionIndex()]; } |
| 271 |
inline const Vec3d & getTextureCoordinate(int textureCoordinateIndex) const { return textureCoordinates[textureCoordinateIndex]; } |
| 272 |
inline const Vec3d & getTextureCoordinate(const Vertex & vertex) const { return textureCoordinates[vertex.getTextureCoordinateIndex()]; } |
| 273 |
inline const Vec3d & getNormal(int normalIndex) const { return normals[normalIndex]; } |
| 274 |
inline const Vec3d & getNormal(const Vertex & vertex) const { return normals[vertex.getNormalIndex()]; } |
| 275 |
|
| 276 |
inline void setPosition(int vertexIndex, const Vec3d & position) { vertexPositions[vertexIndex] = position; } |
| 277 |
inline void setPosition(Vertex & vertex, const Vec3d & position) { vertexPositions[vertex.getPositionIndex()] = position; } |
| 278 |
inline void setTextureCoordinate(int textureCoordinateIndex, const Vec3d & textureCoordinate) { textureCoordinates[textureCoordinateIndex] = textureCoordinate; } |
| 279 |
inline void setTextureCoordinate(Vertex & vertex, const Vec3d & textureCoordinate) { textureCoordinates[vertex.getTextureCoordinateIndex()] = textureCoordinate; } |
| 280 |
inline void setNormal(int normalIndex, const Vec3d & normal) { normals[normalIndex] = normal; } |
| 281 |
inline void setNormal(Vertex & vertex, const Vec3d & normal) { normals[vertex.getNormalIndex()] = normal; } |
| 282 |
|
| 283 |
Group getGroup(const std::string name) const; |
| 284 |
unsigned int getGroupIndex(const std::string name) const; |
| 285 |
|
| 286 |
inline const Group * getGroupHandle(unsigned int groupIndex) const { return &(groups[groupIndex]); } |
| 287 |
inline Group * getGroupHandle(unsigned int groupIndex) { return &(groups[groupIndex]); } |
| 288 |
|
| 289 |
inline const Material & getMaterial(unsigned int materialIndex) const { return materials[materialIndex]; } |
| 290 |
unsigned int getMaterialIndex(const std::string name) const; |
| 291 |
|
| 292 |
inline const Material * getMaterialHandle(unsigned int materialIndex) const { return &materials[materialIndex]; } |
| 293 |
inline Material * getMaterialHandle(unsigned int materialIndex) { return &materials[materialIndex]; } |
| 294 |
void setMaterialAlpha(double alpha); |
| 295 |
void setSingleMaterial(const Material & material); |
| 296 |
int usesTextureMapping(); |
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
void addDefaultMaterial(); |
| 301 |
inline void addMaterial(const Material & material) { materials.push_back(material); } |
| 302 |
inline void addMaterial(const std::string & name, const Vec3d & Ka, const Vec3d & Kd, const Vec3d & Ks, double shininess, const std::string textureFilename=std::string()) { materials.push_back(Material(name, Ka, Kd, Ks, shininess, textureFilename));} |
| 303 |
inline void addGroup(const Group & group) { groups.push_back(group);} |
| 304 |
inline void addGroup(const std::string & name) { groups.push_back(Group(name));} |
| 305 |
void removeGroup(const int groupIndex); |
| 306 |
void removeGroup(const std::string name); |
| 307 |
void removeAllGroups(); |
| 308 |
inline void addVertexPosition (const Vec3d & pos) { vertexPositions.push_back(pos); } |
| 309 |
inline void addVertexNormal (const Vec3d & normal) { normals.push_back(normal); } |
| 310 |
inline void addTextureCoordinate (const Vec3d & textCoord) { textureCoordinates.push_back(textCoord); } |
| 311 |
inline void addFaceToGroup(const Face & face, unsigned int group) { groups[group].addFace(face); } |
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
void computePseudoNormals(); |
| 318 |
inline const Vec3d & getPseudoNormal(unsigned int i) const { return pseudoNormals[i]; } |
| 319 |
|
| 320 |
void computeEdgePseudoNormals(); |
| 321 |
int getEdgePseudoNormal(unsigned int i, unsigned int j, Vec3d * pseudoNormal) const; |
| 322 |
|
| 323 |
void buildVertexFaceNeighbors(); |
| 324 |
void clearVertexFaceNeighbors(); |
| 325 |
void buildVertexNormals(double angle); |
| 326 |
void buildVertexNormalsFancy(double angle); |
| 327 |
|
| 328 |
void computeSurfaceAreaPerVertex(); |
| 329 |
inline double getSurfaceAreaPerVertex(unsigned int i) const { return surfaceAreaPerVertex[i]; } |
| 330 |
|
| 331 |
void initSurfaceSampling(); |
| 332 |
Vec3d getSurfaceSamplePosition(double sample) const; |
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
void initTriangleLookup(); |
| 337 |
void clearTriangleLookup(); |
| 338 |
void getTriangle(int triangleIndex, int * vtxA, int * vtxB, int * vtxC); |
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
bool isTriangularMesh() const; |
| 343 |
bool isQuadrilateralMesh() const; |
| 344 |
|
| 345 |
int computeNumIsolatedVertices() const; |
| 346 |
unsigned int computeMaxFaceDegree() const; |
| 347 |
|
| 348 |
double computeMinEdgeLength() const; |
| 349 |
double computeMedianEdgeLength() const; |
| 350 |
double computeAverageEdgeLength() const; |
| 351 |
double computeMaxEdgeLength() const; |
| 352 |
|
| 353 |
double computeMinEdgeLength(int * vtxa, int * vtxb) const; |
| 354 |
double computeMaxEdgeLength(int * vtxa, int * vtxb) const; |
| 355 |
|
| 356 |
|
| 357 |
|
| 358 |
double computeVolume() const; |
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
void getBoundingBox(double expansionRatio, Vec3d * bmin, Vec3d * bmax) const; |
| 363 |
void getCubicBoundingBox(double expansionRatio, Vec3d * bmin, Vec3d * bmax) const; |
| 364 |
double getDiameter() const; |
| 365 |
|
| 366 |
void getMeshRadius(const Vec3d & centroid, double * radius) const; |
| 367 |
void getMeshGeometricParameters(Vec3d * centroid, double * radius) const; |
| 368 |
|
| 369 |
void exportGeometry(int * numVertices, double ** vertices, int * numTriangles = NULL, int ** triangles = NULL, |
| 370 |
int * numGroups = NULL, int ** triangleGroups = NULL) const; |
| 371 |
void exportFaceGeometry(int * numVertices, double ** vertices, int * numFaces = NULL, int ** faceCardinalities = NULL, int ** faces = NULL, |
| 372 |
int * numGroups = NULL, int ** faceGroups = NULL) const; |
| 373 |
void exportUVGeometry(int * numUVVertices, double ** UVVertices, int * numUVTriangles, int ** UVTriangles) const; |
| 374 |
|
| 375 |
Vec3d computeFaceCentroid(const Face & face) const; |
| 376 |
double computeFaceSurfaceArea(const Face & face) const; |
| 377 |
void computeFaceSurfaceAreas(std::vector<double> & surfaceAreas) const; |
| 378 |
|
| 379 |
|
| 380 |
Vec3d computeFaceNormal(const Face & face) const; |
| 381 |
void buildFaceNormals(); |
| 382 |
|
| 383 |
double computeMass(const std::vector<double> & groupSurfaceMassDensities) const; |
| 384 |
Vec3d computeCenterOfMass_Vertices() const; |
| 385 |
Vec3d computeCenterOfMass_Triangles() const; |
| 386 |
|
| 387 |
Vec3d computeCenterOfMass_Triangles(const std::vector<double> & groupSurfaceMassDensities) const; |
| 388 |
|
| 389 |
void computeInertiaTensor_Triangles(double IT[6]) const; |
| 390 |
void computeInertiaTensor_Triangles(double mass, double IT[6]) const; |
| 391 |
void computeInertiaTensor_Triangles(const std::vector<double> & groupSurfaceMassDensities, double IT[6]) const; |
| 392 |
|
| 393 |
static double computeTriangleSurfaceArea(Vec3d & p0, Vec3d & p1, Vec3d & p2); |
| 394 |
double computeSurfaceArea() const; |
| 395 |
void computeSurfaceAreaPerGroup(std::vector<double> & surfaceAreas) const; |
| 396 |
|
| 397 |
void computeMassPerVertex(const std::vector<double> & groupSurfaceMassDensities, std::vector<double> & masses) const; |
| 398 |
|
| 399 |
|
| 400 |
unsigned int getClosestVertex(const Vec3d & queryPos, double * distance=NULL) const; |
| 401 |
|
| 402 |
void computeCentroids(std::vector<Vec3d> & centroids) const; |
| 403 |
void interpolateToCentroids(const std::vector<double> & nodalData, std::vector<double> & centroidData) const; |
| 404 |
void interpolateToCentroids(const std::vector<Vec3d> & nodalData, std::vector<Vec3d> & centroidData) const; |
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
void triangulate(); |
| 409 |
|
| 410 |
void scaleUniformly(const Vec3d & center, double factor); |
| 411 |
void transformRigidly(const Vec3d & translation, const Mat3d & rotation); |
| 412 |
void deform(double * u); |
| 413 |
|
| 414 |
int removeDuplicatedMaterials(); |
| 415 |
int removeIsolatedVertices(); |
| 416 |
int removeIsolatedTextureCoordinates(); |
| 417 |
int removeIsolatedNormals(); |
| 418 |
int removeZeroAreaFaces(int verbose=0); |
| 419 |
|
| 420 |
|
| 421 |
int removeHangingFaces(); |
| 422 |
|
| 423 |
|
| 424 |
int removeNonManifoldEdges(); |
| 425 |
void collapseEdge(unsigned int vertexA, unsigned int vertexB, int removeIsolatedVertices=1); |
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
|
| 430 |
void setNormalsToAverageFaceNormals(); |
| 431 |
|
| 432 |
void setNormalsToFaceNormals(); |
| 433 |
|
| 434 |
void setNormalsToPseudoNormals(); |
| 435 |
|
| 436 |
void renumberVertices(const std::vector<int> & permutation); |
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
void mergeGroups(const std::vector<int> & groupIndices); |
| 442 |
|
| 443 |
void removeEmptyGroups(); |
| 444 |
|
| 445 |
void appendMesh(ObjMesh * mesh); |
| 446 |
|
| 447 |
|
| 448 |
|
| 449 |
|
| 450 |
ObjMesh * clone(const std::vector<std::pair<int, int> > & groupsAndFaces, int removeIsolatedVertices=1) const; |
| 451 |
|
| 452 |
|
| 453 |
|
| 454 |
|
| 455 |
ObjMesh * splitIntoConnectedComponents(int withinGroupsOnly=0, int verbose=0) const; |
| 456 |
|
| 457 |
ObjMesh * extractGroup(unsigned int group, int keepOnlyUsedNormals = 1, int keepOnlyUsedTextureCoordinates = 1) const; |
| 458 |
|
| 459 |
|
| 460 |
|
| 461 |
|
| 462 |
void save(const std::string & filename, int outputMaterials=0, fileFormatType fileFormat = ASCII, int verbose=1) const; |
| 463 |
|
| 464 |
static int saveObjMeshesToBinary(const std::string & binaryFilename, int numObjMeshes, ObjMesh ** objMeshes, int * saveObjMeshesFlag, int outputMaterials = 0, int verbose = 0); |
| 465 |
|
| 466 |
|
| 467 |
void saveToStl(const std::string & filename) const; |
| 468 |
|
| 469 |
|
| 470 |
void saveToSmesh(const std::string & filename) const; |
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
void saveToAbq(const std::string & filename) const; |
| 475 |
|
| 476 |
|
| 477 |
static void dirname(const char * path, char * result); |
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
static int loadObjMeshesFromBinary(const std::string & binaryFilename, int * numObjMeshes, ObjMesh *** objMeshes, int verbose = 0); |
| 484 |
|
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
void computeBoundingBox(); |
| 489 |
|
| 490 |
inline static bool isNaN(double x) { return Vec3d::isNaN(x); } |
| 491 |
|
| 492 |
protected: |
| 493 |
|
| 494 |
static int loadObjMeshesFromBinary(FILE * fin, int * numObjMeshes, ObjMesh *** objMeshes, int verbose = 0); |
| 495 |
|
| 496 |
|
| 497 |
|
| 498 |
static unsigned int readFromMemory(void * buf, unsigned int elementSize, unsigned int numElements, void * memoryLocation); |
| 499 |
static unsigned int readFromFile(void * buf, unsigned int elementSize, unsigned int numElements, void * fin); |
| 500 |
int loadFromAscii(const std::string & filename, int verbose = 0); |
| 501 |
int loadFromBinary(const std::string & filename, int verbose = 0); |
| 502 |
int loadFromBinary(void * binaryInputStream, streamType stream = FILE_STREAM, int verbose = 0); |
| 503 |
|
| 504 |
|
| 505 |
void saveToAscii(const std::string & filename, int outputMaterials=0, int verbose=1) const; |
| 506 |
|
| 507 |
|
| 508 |
int saveToBinary(const std::string & filename, int outputMaterials = 0, int verbose = 0) const; |
| 509 |
int saveToBinary(FILE * binaryOutputStream, int outputMaterials = 0, unsigned int * bytesWritten = NULL, bool countBytesOnly = false, int verbose = 0) const; |
| 510 |
|
| 511 |
std::vector< Material > materials; |
| 512 |
std::vector< Group > groups; |
| 513 |
std::vector< Vec3d > vertexPositions; |
| 514 |
std::vector< Vec3d > textureCoordinates; |
| 515 |
std::vector< Vec3d > normals; |
| 516 |
std::string filename; |
| 517 |
|
| 518 |
double diameter; |
| 519 |
Vec3d bmin, bmax; |
| 520 |
Vec3d center, cubeHalf; |
| 521 |
|
| 522 |
std::vector<double> surfaceAreaPerVertex; |
| 523 |
std::vector<Vec3d> pseudoNormals; |
| 524 |
|
| 525 |
std::vector<int> triangles; |
| 526 |
|
| 527 |
|
| 528 |
std::map< std::pair<unsigned int,unsigned int>, Vec3d > edgePseudoNormals; |
| 529 |
|
| 530 |
|
| 531 |
class VertexFaceNeighbor |
| 532 |
{ |
| 533 |
public: |
| 534 |
explicit VertexFaceNeighbor(int groupIndex_, int faceIndex_, int faceVertexIndex_, bool averaged_=false) : groupIndex(groupIndex_), faceIndex(faceIndex_), faceVertexIndex(faceVertexIndex_), averaged(averaged_) {} |
| 535 |
|
| 536 |
inline int getGroupIndex() const { return groupIndex; } |
| 537 |
inline int getFaceIndex() const { return faceIndex; } |
| 538 |
inline int getFaceVertexIndex() const { return faceVertexIndex; } |
| 539 |
inline bool getAveraged() const { return averaged; } |
| 540 |
|
| 541 |
inline void setAveraged(bool averaged_) { averaged = averaged_; } |
| 542 |
|
| 543 |
protected: |
| 544 |
int groupIndex; |
| 545 |
int faceIndex; |
| 546 |
int faceVertexIndex; |
| 547 |
bool averaged; |
| 548 |
}; |
| 549 |
|
| 550 |
std::vector<std::list<VertexFaceNeighbor> > vertexFaceNeighbors; |
| 551 |
|
| 552 |
|
| 553 |
void computeSpecificInertiaTensor(Vec3d & v0, Vec3d & v1, Vec3d & v2, double t[6]) const; |
| 554 |
|
| 555 |
void parseMaterials(const std::string & objMeshname, const std::string & materialFilename, int verbose=1); |
| 556 |
|
| 557 |
std::vector<std::pair<double, const Face*> > surfaceSamplingAreas; |
| 558 |
|
| 559 |
static void removeWhitespace(char * s); |
| 560 |
static void convertWhitespaceToSingleBlanks(char * s); |
| 561 |
|
| 562 |
static void fgets_(char * s, int n, FILE * stream); |
| 563 |
}; |
| 564 |
|
| 565 |
#endif |
| 566 |
|