Commit 0382c011 authored by Mike Kremer's avatar Mike Kremer
Browse files

OBJ reader can now read splines again.

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@11763 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 620f9a6d
......@@ -331,6 +331,8 @@ void FileOBJPlugin::createAllGroupObjects(OBJImporter& _importer) {
else if (_importer.isCurve( i )) {
std::cerr << "Creating curve" << std::endl;
int id = -1;
emit addEmptyObject(DATA_BSPLINE_CURVE, id);
......@@ -540,6 +542,9 @@ void FileOBJPlugin::readOBJFile(QString _filename, OBJImporter& _importer)
std::string keyWrd;
std::string nextKeyWrd = "";
unsigned int curveCount = 0;
unsigned int surfaceCount = 0;
float x, y, z, u, v;
int deg, index;
double knot;
......@@ -692,17 +697,10 @@ void FileOBJPlugin::readOBJFile(QString _filename, OBJImporter& _importer)
std::string groupName;
std::getline(stream, groupName);
// if ( faceCount > 0 )
// addNewObject( _importer, QString(groupName.c_str()) );
//else {
if(faceCount == 0) {
currentFileName = QString(groupName.c_str());
}
//since obj-groups are used, all new objects will be grouped together in OpenFlipper
// if ( _importer.objectOptions().size() > 1 )
// _importer.setGroup( QFileInfo(_filename).fileName() );
int id = _importer.groupId(groupName.c_str());
if(id == -1) {
std::cerr << "Error: Group has not been added before!" << std::endl;
......@@ -722,10 +720,6 @@ void FileOBJPlugin::readOBJFile(QString _filename, OBJImporter& _importer)
vhandles.clear();
face_texcoords.clear();
//add object if not already there
// if (_importer.currentObject() == -1)
// addNewObject(_importer, currentFileName );
// read full line after detecting a face
std::string faceLine;
......@@ -896,8 +890,16 @@ void FileOBJPlugin::readOBJFile(QString _filename, OBJImporter& _importer)
mode = CURVE;
// if ( keyWrd == "curv" )
// addNewObject(_importer, currentFileName );
if ( keyWrd == "curv" ) {
int id = _importer.groupId(QString("spline_curve_%1").arg(curveCount));
if(id == -1) {
std::cerr << "Error: Group has not been added before!" << std::endl;
return;
}
_importer.setCurrentGroup(id);
curveCount++;
}
//get curve control points
std::string curveLine;
......@@ -1005,8 +1007,9 @@ void FileOBJPlugin::readOBJFile(QString _filename, OBJImporter& _importer)
lineData >> knot;
if ( !lineData.fail() )
if ( !lineData.fail() ) {
knots->push_back( knot );
}
}
}
......@@ -1015,8 +1018,16 @@ void FileOBJPlugin::readOBJFile(QString _filename, OBJImporter& _importer)
mode = SURFACE;
// if ( keyWrd == "surf" )
// addNewObject(_importer, currentFileName );
if ( keyWrd == "surf" ) {
int id = _importer.groupId(QString("spline_surface_%1").arg(surfaceCount));
if(id == -1) {
std::cerr << "Error: Group has not been added before!" << std::endl;
return;
}
_importer.setCurrentGroup(id);
surfaceCount++;
}
//get surface control points
std::string surfLine;
......@@ -1066,7 +1077,7 @@ void FileOBJPlugin::readOBJFile(QString _filename, OBJImporter& _importer)
// compute number of control points in m and in n direction
int dimU = knotsU.size() - _importer.degreeU() - 1;
int dimV = knotsV.size() - _importer.degreeV() - 1;
// add the control points
std::vector< ACG::Vec3d > controlPolygon;
......@@ -1083,6 +1094,8 @@ void FileOBJPlugin::readOBJFile(QString _filename, OBJImporter& _importer)
_importer.currentSurface()->set_knots_m(knotsU);
_importer.currentSurface()->set_knots_n(knotsV);
}
cpIndices.clear();
......@@ -1114,6 +1127,9 @@ void FileOBJPlugin::checkTypes(QString _filename, OBJImporter& _importer, QStrin
std::string keyWrd;
std::string nextKeyWrd = "";
unsigned int curveCount = 0;
unsigned int surfaceCount = 0;
float x, y, z;
int index;
int faceCount = 0;
......@@ -1184,7 +1200,7 @@ void FileOBJPlugin::checkTypes(QString _filename, OBJImporter& _importer, QStrin
// group
else if (mode == NONE && keyWrd == "g"){
//if ( faceCount > 0 ){
//give options to importer and reinitialize
//for next object
......@@ -1200,7 +1216,6 @@ void FileOBJPlugin::checkTypes(QString _filename, OBJImporter& _importer, QStrin
_importer.setObjectOptions( options );
options = OBJImporter::TRIMESH;
faceCount = 0;
//}
}
// face
else if (mode == NONE && keyWrd == "f"){
......@@ -1275,16 +1290,18 @@ void FileOBJPlugin::checkTypes(QString _filename, OBJImporter& _importer, QStrin
mode = CURVE;
if ( keyWrd == "curv" ){
if ( faceCount > 0 ){
//give options to importer and reinitialize
//for next object
if ( options & OBJImporter::TRIMESH ) TriMeshCount++;
if ( options & OBJImporter::POLYMESH ) PolyMeshCount++;
if ( keyWrd == "curv" ) {
_importer.setObjectOptions( options );
}
//give options to importer and reinitialize
//for next object
if ( options & OBJImporter::TRIMESH ) TriMeshCount++;
if ( options & OBJImporter::POLYMESH ) PolyMeshCount++;
int id = _importer.addGroup(QString("spline_curve_%1").arg(curveCount));
_importer.setCurrentGroup(id);
curveCount++;
_importer.setObjectOptions( options );
options = OBJImporter::CURVE;
}
......@@ -1343,14 +1360,16 @@ void FileOBJPlugin::checkTypes(QString _filename, OBJImporter& _importer, QStrin
if ( keyWrd == "surf" ){
if ( faceCount > 0 ){
//give options to importer and reinitialize
//for next object
if ( options & OBJImporter::TRIMESH ) TriMeshCount++;
if ( options & OBJImporter::POLYMESH ) PolyMeshCount++;
//give options to importer and reinitialize
//for next object
if ( options & OBJImporter::TRIMESH ) TriMeshCount++;
if ( options & OBJImporter::POLYMESH ) PolyMeshCount++;
_importer.setObjectOptions( options );
}
int id = _importer.addGroup(QString("spline_surface_%1").arg(surfaceCount));
_importer.setCurrentGroup(id);
surfaceCount++;
_importer.setObjectOptions( options );
options = OBJImporter::SURFACE;
}
......
......@@ -122,22 +122,34 @@ int OBJImporter::degreeV(){
/// add a mesh
void OBJImporter::setObject(BaseObject* _object, int _groupId) {
while ((unsigned int)_groupId >= objects_.size()) {
objects_.push_back(NULL);
if((unsigned int)_groupId >= triMeshes_.size()) {
std::cerr << "Error: Group does not exist!" << std::endl;
return;
}
if (objects_[_groupId] != NULL)
return;
if(PluginFunctions::polyMeshObject(_object->id()) != NULL) {
if (_object != NULL) {
polyMeshes_[_groupId] = PluginFunctions::polyMeshObject(_object->id());
addUsedVertices(_groupId);
objects_[_groupId] = _object;
} else if(PluginFunctions::triMeshObject(_object->id()) != NULL) {
if(PluginFunctions::polyMesh(_object->id()) != NULL || PluginFunctions::triMesh(_object->id()) != NULL) {
addUsedVertices(_groupId);
}
triMeshes_[_groupId] = PluginFunctions::triMeshObject(_object->id());
addUsedVertices(_groupId);
}
#ifdef ENABLE_BSPLINECURVE_SUPPORT
else if(PluginFunctions::bsplineCurveObject(PluginFunctions::baseObjectData(_object)) != NULL) {
} else {
bSplineCurves_[_groupId] = PluginFunctions::bsplineCurveObject(PluginFunctions::baseObjectData(_object));
}
#endif
#ifdef ENABLE_BSPLINESURFACE_SUPPORT
else if(PluginFunctions::bsplineSurfaceObject(PluginFunctions::baseObjectData(_object)) != NULL) {
bSplineSurfaces_[_groupId] = PluginFunctions::bsplineSurfaceObject(PluginFunctions::baseObjectData(_object));
}
#endif
else {
std::cerr << "Error: Cannot add object. Type is unknown!" << std::endl;
}
}
......@@ -155,7 +167,7 @@ int OBJImporter::currentObject(){
/// get the active polyMesh
PolyMesh* OBJImporter::currentPolyMesh(){
return PluginFunctions::polyMesh(object(currentObject())->id());
return polyMeshes_[currentGroup_]->mesh();
}
//-----------------------------------------------------------------------------
......@@ -163,7 +175,7 @@ PolyMesh* OBJImporter::currentPolyMesh(){
/// get the active triMesh
TriMesh* OBJImporter::currentTriMesh(){
return PluginFunctions::triMesh(object(currentObject())->id());
return triMeshes_[currentGroup_]->mesh();
}
//-----------------------------------------------------------------------------
......@@ -172,7 +184,7 @@ TriMesh* OBJImporter::currentTriMesh(){
BSplineCurve* OBJImporter::currentCurve(){
return PluginFunctions::splineCurve(PluginFunctions::baseObjectData(object(currentObject())));
return bSplineCurves_[currentGroup_]->splineCurve();
}
#endif
......@@ -183,7 +195,7 @@ BSplineCurve* OBJImporter::currentCurve(){
BSplineSurface* OBJImporter::currentSurface(){
return PluginFunctions::splineSurface(PluginFunctions::baseObjectData(object(currentObject())));
return bSplineSurfaces_[currentGroup_]->splineSurface();
}
#endif
......@@ -193,12 +205,10 @@ BSplineSurface* OBJImporter::currentSurface(){
/// add all vertices that are used to the mesh (in correct order)
void OBJImporter::addUsedVertices(int _groupId) {
BaseObject* obj = objects_[_groupId];
if (isTriangleMesh(_groupId)) {
//handle triangle meshes
TriMesh* curMesh = PluginFunctions::triMesh(obj->id());
TriMesh* curMesh = triMeshes_[_groupId]->mesh();
if (curMesh == NULL)
return;
......@@ -219,7 +229,7 @@ void OBJImporter::addUsedVertices(int _groupId) {
} else if (isPolyMesh(_groupId)) {
//handle triangle meshes
PolyMesh* curMesh = PluginFunctions::polyMesh(obj->id());
PolyMesh* curMesh = polyMeshes_[_groupId]->mesh();
if (curMesh == NULL)
return;
......@@ -710,17 +720,22 @@ uint OBJImporter::n_texCoords(){
//-----------------------------------------------------------------------------
uint OBJImporter::objectCount(){
return objects_.size();
return groupNames_.size();
}
//-----------------------------------------------------------------------------
BaseObject* OBJImporter::object(int _objectID) {
if (objects_.size() == 0 || (int)objects_.size() <= _objectID)
if (objectCount() == 0 || objectCount() <= (unsigned int)_objectID)
return NULL;
else
return objects_[ _objectID ];
if(triMeshes_[_objectID] != NULL) return triMeshes_[_objectID];
else if(polyMeshes_[_objectID] != NULL) return polyMeshes_[_objectID];
else if(bSplineCurves_[_objectID] != NULL) return bSplineCurves_[_objectID];
else if(bSplineSurfaces_[_objectID] != NULL) return bSplineSurfaces_[_objectID];
return NULL;
}
//-----------------------------------------------------------------------------
......@@ -790,6 +805,15 @@ int OBJImporter::addGroup(const QString& _groupName) {
vertexMapTri_.push_back(std::map<int,TriMesh::VertexHandle>());
vertexMapPoly_.push_back(std::map<int,TriMesh::VertexHandle>());
addedFacesTri_.push_back(std::vector< TriMesh::FaceHandle>());
triMeshes_.push_back(NULL);
polyMeshes_.push_back(NULL);
#ifdef ENABLE_BSPLINECURVE_SUPPORT
bSplineCurves_.push_back(NULL);
#endif
#ifdef ENABLE_BSPLINESURFACE_SUPPORT
bSplineSurfaces_.push_back(NULL);
#endif
return groupNames_.size() - 1;
}
return id;
......
......@@ -231,17 +231,6 @@ class OBJImporter
void setCurrentGroup(const int _current);
int currentGroup() const;
void stats() {
std::cerr << std::endl << "Num groups: " << numGroups() << std::endl;
int i = 0;
for(std::vector<QString>::const_iterator it = groupNames_.begin();
it != groupNames_.end(); ++it) {
std::cerr << it->toStdString() << ", num vs: " << usedVertices_[i].size() <<
", Type: " << (objectOptions_[i] == TRIMESH ? "TriMesh" : "PolyMesh") << std::endl;
++i;
}
}
/// Finish up importing:
/// Duplicate vertices of non-manifold faces and
/// add new face as isolated one
......@@ -274,8 +263,17 @@ class OBJImporter
std::vector<std::vector< TriMesh::FaceHandle > > addedFacesTri_;
//std::vector< BaseObject* > objects_;
//object data
std::vector< BaseObject* > objects_;
std::vector<TriMeshObject*> triMeshes_;
std::vector<PolyMeshObject*> polyMeshes_;
#ifdef ENABLE_BSPLINECURVE_SUPPORT
std::vector<BSplineCurveObject*> bSplineCurves_;
#endif
#ifdef ENABLE_BSPLINESURFACE_SUPPORT
std::vector<BSplineSurfaceObject*> bSplineSurfaces_;
#endif
std::vector< ObjectOptions > objectOptions_;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment