improve groups handling of obj mesh format
This commit is contained in:
parent
39e577817a
commit
cc78503935
|
@ -167,10 +167,15 @@ private:
|
||||||
unsigned long segmct = mesh.countSegments();
|
unsigned long segmct = mesh.countSegments();
|
||||||
if (segmct > 1) {
|
if (segmct > 1) {
|
||||||
for (unsigned long i=0; i<segmct; i++) {
|
for (unsigned long i=0; i<segmct; i++) {
|
||||||
std::auto_ptr<MeshObject> segm(mesh.meshFromSegment(mesh.getSegment(i).getIndices()));
|
const Segment& group = mesh.getSegment(i);
|
||||||
|
std::string groupName = group.getName();
|
||||||
|
if (groupName.empty())
|
||||||
|
groupName = file.fileNamePure();
|
||||||
|
|
||||||
|
std::auto_ptr<MeshObject> segm(mesh.meshFromSegment(group.getIndices()));
|
||||||
Mesh::Feature *pcFeature = static_cast<Mesh::Feature *>
|
Mesh::Feature *pcFeature = static_cast<Mesh::Feature *>
|
||||||
(pcDoc->addObject("Mesh::Feature", file.fileNamePure().c_str()));
|
(pcDoc->addObject("Mesh::Feature", groupName.c_str()));
|
||||||
pcFeature->Label.setValue(file.fileNamePure().c_str());
|
pcFeature->Label.setValue(groupName.c_str());
|
||||||
pcFeature->Mesh.swapMesh(*segm);
|
pcFeature->Mesh.swapMesh(*segm);
|
||||||
pcFeature->purgeTouched();
|
pcFeature->purgeTouched();
|
||||||
}
|
}
|
||||||
|
@ -227,10 +232,15 @@ private:
|
||||||
unsigned long segmct = mesh.countSegments();
|
unsigned long segmct = mesh.countSegments();
|
||||||
if (segmct > 1) {
|
if (segmct > 1) {
|
||||||
for (unsigned long i=0; i<segmct; i++) {
|
for (unsigned long i=0; i<segmct; i++) {
|
||||||
std::auto_ptr<MeshObject> segm(mesh.meshFromSegment(mesh.getSegment(i).getIndices()));
|
const Segment& group = mesh.getSegment(i);
|
||||||
|
std::string groupName = group.getName();
|
||||||
|
if (groupName.empty())
|
||||||
|
groupName = file.fileNamePure();
|
||||||
|
|
||||||
|
std::auto_ptr<MeshObject> segm(mesh.meshFromSegment(group.getIndices()));
|
||||||
Mesh::Feature *pcFeature = static_cast<Mesh::Feature *>
|
Mesh::Feature *pcFeature = static_cast<Mesh::Feature *>
|
||||||
(pcDoc->addObject("Mesh::Feature", file.fileNamePure().c_str()));
|
(pcDoc->addObject("Mesh::Feature", groupName.c_str()));
|
||||||
pcFeature->Label.setValue(file.fileNamePure().c_str());
|
pcFeature->Label.setValue(groupName.c_str());
|
||||||
pcFeature->Mesh.swapMesh(*segm);
|
pcFeature->Mesh.swapMesh(*segm);
|
||||||
pcFeature->purgeTouched();
|
pcFeature->purgeTouched();
|
||||||
}
|
}
|
||||||
|
|
|
@ -255,6 +255,7 @@ bool MeshInput::LoadSTL (std::istream &rstrIn)
|
||||||
/** Loads an OBJ file. */
|
/** Loads an OBJ file. */
|
||||||
bool MeshInput::LoadOBJ (std::istream &rstrIn)
|
bool MeshInput::LoadOBJ (std::istream &rstrIn)
|
||||||
{
|
{
|
||||||
|
boost::regex rx_g("^g\\s+([\\x21-\\x7E]+)\\s*$");
|
||||||
boost::regex rx_p("^v\\s+([-+]?[0-9]*)\\.?([0-9]+([eE][-+]?[0-9]+)?)"
|
boost::regex rx_p("^v\\s+([-+]?[0-9]*)\\.?([0-9]+([eE][-+]?[0-9]+)?)"
|
||||||
"\\s+([-+]?[0-9]*)\\.?([0-9]+([eE][-+]?[0-9]+)?)"
|
"\\s+([-+]?[0-9]*)\\.?([0-9]+([eE][-+]?[0-9]+)?)"
|
||||||
"\\s+([-+]?[0-9]*)\\.?([0-9]+([eE][-+]?[0-9]+)?)\\s*$");
|
"\\s+([-+]?[0-9]*)\\.?([0-9]+([eE][-+]?[0-9]+)?)\\s*$");
|
||||||
|
@ -284,7 +285,6 @@ bool MeshInput::LoadOBJ (std::istream &rstrIn)
|
||||||
std::string line;
|
std::string line;
|
||||||
float fX, fY, fZ;
|
float fX, fY, fZ;
|
||||||
unsigned int i1=1,i2=1,i3=1,i4=1;
|
unsigned int i1=1,i2=1,i3=1,i4=1;
|
||||||
MeshGeomFacet clFacet;
|
|
||||||
MeshFacet item;
|
MeshFacet item;
|
||||||
|
|
||||||
if (!rstrIn || rstrIn.bad() == true)
|
if (!rstrIn || rstrIn.bad() == true)
|
||||||
|
@ -295,19 +295,20 @@ bool MeshInput::LoadOBJ (std::istream &rstrIn)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
MeshIO::Binding rgb_value = MeshIO::OVERALL;
|
MeshIO::Binding rgb_value = MeshIO::OVERALL;
|
||||||
bool readvertices=false;
|
bool new_segment = true;
|
||||||
while (std::getline(rstrIn, line)) {
|
while (std::getline(rstrIn, line)) {
|
||||||
|
// when a group name comes don't make it lower case
|
||||||
|
if (!line.empty() && line[0] != 'g') {
|
||||||
for (std::string::iterator it = line.begin(); it != line.end(); ++it)
|
for (std::string::iterator it = line.begin(); it != line.end(); ++it)
|
||||||
*it = tolower(*it);
|
*it = tolower(*it);
|
||||||
|
}
|
||||||
if (boost::regex_match(line.c_str(), what, rx_p)) {
|
if (boost::regex_match(line.c_str(), what, rx_p)) {
|
||||||
readvertices = true;
|
|
||||||
fX = (float)std::atof(what[1].first);
|
fX = (float)std::atof(what[1].first);
|
||||||
fY = (float)std::atof(what[4].first);
|
fY = (float)std::atof(what[4].first);
|
||||||
fZ = (float)std::atof(what[7].first);
|
fZ = (float)std::atof(what[7].first);
|
||||||
meshPoints.push_back(MeshPoint(Base::Vector3f(fX, fY, fZ)));
|
meshPoints.push_back(MeshPoint(Base::Vector3f(fX, fY, fZ)));
|
||||||
}
|
}
|
||||||
else if (boost::regex_match(line.c_str(), what, rx_c)) {
|
else if (boost::regex_match(line.c_str(), what, rx_c)) {
|
||||||
readvertices = true;
|
|
||||||
fX = (float)std::atof(what[1].first);
|
fX = (float)std::atof(what[1].first);
|
||||||
fY = (float)std::atof(what[4].first);
|
fY = (float)std::atof(what[4].first);
|
||||||
fZ = (float)std::atof(what[7].first);
|
fZ = (float)std::atof(what[7].first);
|
||||||
|
@ -322,7 +323,6 @@ bool MeshInput::LoadOBJ (std::istream &rstrIn)
|
||||||
rgb_value = MeshIO::PER_VERTEX;
|
rgb_value = MeshIO::PER_VERTEX;
|
||||||
}
|
}
|
||||||
else if (boost::regex_match(line.c_str(), what, rx_t)) {
|
else if (boost::regex_match(line.c_str(), what, rx_t)) {
|
||||||
readvertices = true;
|
|
||||||
fX = (float)std::atof(what[1].first);
|
fX = (float)std::atof(what[1].first);
|
||||||
fY = (float)std::atof(what[4].first);
|
fY = (float)std::atof(what[4].first);
|
||||||
fZ = (float)std::atof(what[7].first);
|
fZ = (float)std::atof(what[7].first);
|
||||||
|
@ -336,10 +336,14 @@ bool MeshInput::LoadOBJ (std::istream &rstrIn)
|
||||||
meshPoints.back().SetProperty(prop);
|
meshPoints.back().SetProperty(prop);
|
||||||
rgb_value = MeshIO::PER_VERTEX;
|
rgb_value = MeshIO::PER_VERTEX;
|
||||||
}
|
}
|
||||||
|
else if (boost::regex_match(line.c_str(), what, rx_g)) {
|
||||||
|
new_segment = true;
|
||||||
|
_groupNames.push_back(what[1].first);
|
||||||
|
}
|
||||||
else if (boost::regex_match(line.c_str(), what, rx_f3)) {
|
else if (boost::regex_match(line.c_str(), what, rx_f3)) {
|
||||||
// starts a new segment
|
// starts a new segment
|
||||||
if (readvertices) {
|
if (new_segment) {
|
||||||
readvertices = false;
|
new_segment = false;
|
||||||
segment++;
|
segment++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -353,8 +357,8 @@ bool MeshInput::LoadOBJ (std::istream &rstrIn)
|
||||||
}
|
}
|
||||||
else if (boost::regex_match(line.c_str(), what, rx_f4)) {
|
else if (boost::regex_match(line.c_str(), what, rx_f4)) {
|
||||||
// starts a new segment
|
// starts a new segment
|
||||||
if (readvertices) {
|
if (new_segment) {
|
||||||
readvertices = false;
|
new_segment = false;
|
||||||
segment++;
|
segment++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -70,7 +70,7 @@ struct MeshExport Material
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The MeshInput class is able to read a mesh object from a input stream
|
* The MeshInput class is able to read a mesh object from an input stream
|
||||||
* in various formats.
|
* in various formats.
|
||||||
*/
|
*/
|
||||||
class MeshExport MeshInput
|
class MeshExport MeshInput
|
||||||
|
@ -81,6 +81,9 @@ public:
|
||||||
MeshInput (MeshKernel &rclM, Material* m)
|
MeshInput (MeshKernel &rclM, Material* m)
|
||||||
: _rclMesh(rclM), _material(m){}
|
: _rclMesh(rclM), _material(m){}
|
||||||
virtual ~MeshInput (void) { }
|
virtual ~MeshInput (void) { }
|
||||||
|
const std::vector<std::string>& GetGroupNames() const {
|
||||||
|
return _groupNames;
|
||||||
|
}
|
||||||
|
|
||||||
/// Loads the file, decided by extension
|
/// Loads the file, decided by extension
|
||||||
bool LoadAny(const char* FileName);
|
bool LoadAny(const char* FileName);
|
||||||
|
@ -114,6 +117,7 @@ public:
|
||||||
protected:
|
protected:
|
||||||
MeshKernel &_rclMesh; /**< reference to mesh data structure */
|
MeshKernel &_rclMesh; /**< reference to mesh data structure */
|
||||||
Material* _material;
|
Material* _material;
|
||||||
|
std::vector<std::string> _groupNames;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -362,7 +362,7 @@ bool MeshObject::load(const char* file, MeshCore::Material* mat)
|
||||||
if (!aReader.LoadAny(file))
|
if (!aReader.LoadAny(file))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
swapKernel(kernel);
|
swapKernel(kernel, aReader.GetGroupNames());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -373,16 +373,17 @@ bool MeshObject::load(std::istream& str, MeshCore::MeshIO::Format f, MeshCore::M
|
||||||
if (!aReader.LoadFormat(str, f))
|
if (!aReader.LoadFormat(str, f))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
swapKernel(kernel);
|
swapKernel(kernel, aReader.GetGroupNames());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MeshObject::swapKernel(MeshCore::MeshKernel& kernel)
|
void MeshObject::swapKernel(MeshCore::MeshKernel& kernel,
|
||||||
|
const std::vector<std::string>& g)
|
||||||
{
|
{
|
||||||
_kernel.Swap(kernel);
|
_kernel.Swap(kernel);
|
||||||
// Some file formats define several objects per file (e.g. OBJ).
|
// Some file formats define several objects per file (e.g. OBJ).
|
||||||
// Now we mark each object as an own segment so that we can break
|
// Now we mark each object as an own segment so that we can break
|
||||||
// the object into its orriginal objects again.
|
// the object into its original objects again.
|
||||||
this->_segments.clear();
|
this->_segments.clear();
|
||||||
const MeshCore::MeshFacetArray& faces = _kernel.GetFacets();
|
const MeshCore::MeshFacetArray& faces = _kernel.GetFacets();
|
||||||
MeshCore::MeshFacetArray::_TConstIterator it;
|
MeshCore::MeshFacetArray::_TConstIterator it;
|
||||||
|
@ -407,6 +408,13 @@ void MeshObject::swapKernel(MeshCore::MeshKernel& kernel)
|
||||||
this->_segments.push_back(Segment(this,segment,true));
|
this->_segments.push_back(Segment(this,segment,true));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// apply the group names to the segments
|
||||||
|
if (this->_segments.size() == g.size()) {
|
||||||
|
for (std::size_t index = 0; index < this->_segments.size(); index++) {
|
||||||
|
this->_segments[index].setName(g[index]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#ifndef FC_DEBUG
|
#ifndef FC_DEBUG
|
||||||
try {
|
try {
|
||||||
MeshCore::MeshEvalNeighbourhood nb(_kernel);
|
MeshCore::MeshEvalNeighbourhood nb(_kernel);
|
||||||
|
|
|
@ -376,7 +376,7 @@ private:
|
||||||
void deletedFacets(const std::vector<unsigned long>& remFacets);
|
void deletedFacets(const std::vector<unsigned long>& remFacets);
|
||||||
void updateMesh(const std::vector<unsigned long>&);
|
void updateMesh(const std::vector<unsigned long>&);
|
||||||
void updateMesh();
|
void updateMesh();
|
||||||
void swapKernel(MeshCore::MeshKernel& m);
|
void swapKernel(MeshCore::MeshKernel& m, const std::vector<std::string>& g);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Base::Matrix4D _Mtrx;
|
Base::Matrix4D _Mtrx;
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
#define MESH_SEGMENT_H
|
#define MESH_SEGMENT_H
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
#include "Facet.h"
|
#include "Facet.h"
|
||||||
#include "Core/Iterator.h"
|
#include "Core/Iterator.h"
|
||||||
|
|
||||||
|
@ -41,17 +42,21 @@ public:
|
||||||
void addIndices(const std::vector<unsigned long>& inds);
|
void addIndices(const std::vector<unsigned long>& inds);
|
||||||
void removeIndices(const std::vector<unsigned long>& inds);
|
void removeIndices(const std::vector<unsigned long>& inds);
|
||||||
const std::vector<unsigned long>& getIndices() const;
|
const std::vector<unsigned long>& getIndices() const;
|
||||||
bool isEmpty() const { return _indices.empty(); };
|
bool isEmpty() const { return _indices.empty(); }
|
||||||
|
|
||||||
const Segment& operator = (const Segment&);
|
const Segment& operator = (const Segment&);
|
||||||
bool operator == (const Segment&) const;
|
bool operator == (const Segment&) const;
|
||||||
|
|
||||||
|
void setName(const std::string& n) { _name = n; }
|
||||||
|
const std::string& getName() const { return _name; }
|
||||||
|
|
||||||
// friends
|
// friends
|
||||||
friend class MeshObject;
|
friend class MeshObject;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
MeshObject* _mesh;
|
MeshObject* _mesh;
|
||||||
std::vector<unsigned long> _indices;
|
std::vector<unsigned long> _indices;
|
||||||
|
std::string _name;
|
||||||
bool _modifykernel;
|
bool _modifykernel;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user