Commit a99b9630 authored by Dirk Wilden's avatar Dirk Wilden
Browse files

curve surface handling included

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@8174 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 4dddf1ee
#include "FileOBJ.hh"
#ifdef ENABLE_BSPLINECURVE_SUPPORT
bool FileOBJPlugin::writeCurve(std::ostream& _out, QString _filename, BSplineCurve* _curve )
{
_out << "# " << _filename.toStdString() << "\n";
// save control points (coordinates)
for (uint i = 0; i < _curve->n_control_points(); ++i){
ACG::Vec3d cp = _curve->get_control_point(i);
_out << "v " << cp[0] << " " << cp[1] << " " << cp[2] << "\n";
}
_out << "cstype bspline\n";
_out << "deg " << _curve->degree() << "\n";
_out << "g " << _filename.toStdString() << "\n";
// save control polygon
_out << "curv " << _curve->get_knot(0) << " " << _curve->get_knot(_curve->n_knots()-1) << " ";
// save control point indices
for (unsigned int i = 0; i < _curve->n_control_points(); ++i)
_out << i+1 << " "; // obj enumerates the cps starting with 1
_out << "\n";
_out << "parm u ";
// save knotvector
for (unsigned int i = 0; i < _curve->n_knots(); ++i)
_out << _curve->get_knot(i) << " ";
_out << "\n";
_out << "end";
return true;
}
#endif
#ifdef ENABLE_BSPLINESURFACE_SUPPORT
bool FileOBJPlugin::writeSurface(std::ostream& _out, QString _filename, BSplineSurface* _surface ){
_out << "# " << _filename.toStdString() << "\n";
// save control net (coordinates)
unsigned int num_cp_m = _surface->n_control_points_m();
unsigned int num_cp_n = _surface->n_control_points_n();
for (unsigned int i = 0; i < num_cp_m; ++i)
{
for (unsigned int j = 0; j < num_cp_n; ++j)
{
ACG::Vec3d cp = (*_surface)(i,j);
_out << "v " << cp[0] << " " << cp[1] << " " << cp[2] << "\n";
}
}
_out << "cstype bspline\n";
_out << "deg " << _surface->degree_m() << " " << _surface->degree_n() << "\n";
_out << "g " << _filename.toStdString() << "\n";
// save control polygon
_out << "surf " << _surface->get_knot_m(0) << " " << _surface->get_knot_m(_surface->n_knots_m()-1) << " "
<< _surface->get_knot_n(0) << " " << _surface->get_knot_n(_surface->n_knots_n()-1) << " ";
// save control point indices
for (unsigned int i = 0; i < num_cp_m; ++i)
for (unsigned int j = 0; j < num_cp_n; ++j)
_out << (i*num_cp_n) + j+1 << " "; // obj enumerates the cps starting with 1
_out << "\n";
_out << "parm u ";
// save knotvector in m direction
for (unsigned int i = 0; i < _surface->n_knots_m(); ++i)
_out << _surface->get_knot_m(i) << " ";
_out << "\n";
_out << "parm v ";
// save knotvector in n direction
for (unsigned int i = 0; i < _surface->n_knots_n(); ++i)
_out << _surface->get_knot_n(i) << " ";
_out << "\n";
_out << "end";
return true;
}
#endif
include (plugin)
if (EXISTS ${CMAKE_SOURCE_DIR}/ObjectTypes/BSplineCurve)
add_definitions (-DENABLE_BSPLINECURVE_SUPPORT)
endif ()
if (EXISTS ${CMAKE_SOURCE_DIR}/ObjectTypes/BSplineSurface)
add_definitions (-DENABLE_BSPLINESURFACE_SUPPORT)
endif ()
openflipper_plugin ()
This diff is collapsed.
......@@ -60,9 +60,23 @@
#include <ObjectTypes/PolyMesh/PolyMesh.hh>
#include <ObjectTypes/TriangleMesh/TriangleMesh.hh>
#ifdef ENABLE_BSPLINECURVE_SUPPORT
#include <ObjectTypes/BSplineCurve/BSplineCurve.hh>
#endif
#ifdef ENABLE_BSPLINESURFACE_SUPPORT
#include <ObjectTypes/BSplineSurface/BSplineSurface.hh>
#endif
#include "OBJImporter.hh"
enum ReaderMode
{
NONE = 0,
CURVE = 1,
SURFACE = 1 << 1
};
class FileOBJPlugin : public QObject, BaseInterface, FileInterface, LoadSaveInterface,
LoggingInterface, ScriptInterface, INIInterface, StatusbarInterface, RPCInterface, TextureInterface
{
......@@ -138,19 +152,16 @@ class FileOBJPlugin : public QObject, BaseInterface, FileInterface, LoadSaveInte
/// Loads Object and converts it to a triangle mesh if possible
int loadObject(QString _filename);
bool saveObject(int _id, QString _filename);
/// load object and force type
int loadObject(QString _filename, DataType _type);
/// Loads a triangle mesh
int loadTriMeshObject(QString _filename);
/// Loads a poly mesh
int loadPolyMeshObject(QString _filename);
bool saveObject(int _id, QString _filename);
QString version() { return QString("1.0"); };
private:
/// Reader functions
void checkTypes(QString _filename, OBJImporter& _importer);
void checkTypes(QString _filename, OBJImporter& _importer, QStringList& _includes);
bool readMaterial(QString _filename, OBJImporter& _importer);
void readOBJFile(QString _filename, OBJImporter& _importer);
......@@ -171,6 +182,15 @@ class FileOBJPlugin : public QObject, BaseInterface, FileInterface, LoadSaveInte
template< class MeshT >
bool writeMesh(std::ostream& _out, QString _filename, MeshT& _mesh );
#ifdef ENABLE_BSPLINECURVE_SUPPORT
bool writeCurve(std::ostream& _out, QString _filename, BSplineCurve* _curve );
#endif
#ifdef ENABLE_BSPLINESURFACE_SUPPORT
bool writeSurface(std::ostream& _out, QString _filename, BSplineSurface* _surface );
#endif
private:
//Option Widgets
......
......@@ -19,6 +19,15 @@ VertexHandle OBJImporter::addVertex(const Vec3f& _point){
return vertices_.size()-1;
}
/// get vertex with given index
Vec3f OBJImporter::vertex(uint _index){
if ( vertices_.size() > _index )
return vertices_[ _index ];
else
return Vec3f();
}
//-----------------------------------------------------------------------------
/// add texture coordinates
......@@ -39,12 +48,49 @@ int OBJImporter::addNormal(const Vec3f& _normal){
//-----------------------------------------------------------------------------
/// set degree U direction
void OBJImporter::setDegreeU(int _degree){
degreeU_ = _degree;
}
//-----------------------------------------------------------------------------
/// set degree V direction
void OBJImporter::setDegreeV(int _degree){
degreeV_ = _degree;
}
//-----------------------------------------------------------------------------
/// get current degree
int OBJImporter::degreeU(){
return degreeU_;
}
//-----------------------------------------------------------------------------
/// get current degree
int OBJImporter::degreeV(){
return degreeV_;
}
//-----------------------------------------------------------------------------
/// add a mesh
void OBJImporter::addObject( BaseObject* _object ){
PolyMeshObject* polyMeshObj = dynamic_cast< PolyMeshObject* > (_object);
TriMeshObject* triMeshObj = dynamic_cast< TriMeshObject* > (_object);
#ifdef ENABLE_BSPLINECURVE_SUPPORT
BSplineCurveObject* curveObject = dynamic_cast< BSplineCurveObject* > (_object);
#endif
#ifdef ENABLE_BSPLINESURFACE_SUPPORT
BSplineSurfaceObject* surfaceObject = dynamic_cast< BSplineSurfaceObject* > (_object);
#endif
if ( polyMeshObj ){
polyMeshes_.push_back( polyMeshObj->mesh() );
......@@ -55,7 +101,25 @@ void OBJImporter::addObject( BaseObject* _object ){
triMeshes_.push_back( triMeshObj->mesh() );
objects_.push_back( _object );
} else {
}
#ifdef ENABLE_BSPLINECURVE_SUPPORT
else if ( curveObject ){
curves_.push_back( curveObject->splineCurve() );
objects_.push_back( _object );
}
#endif
#ifdef ENABLE_BSPLINESURFACE_SUPPORT
else if ( surfaceObject ){
surfaces_.push_back( surfaceObject->splineSurface() );
objects_.push_back( _object );
}
#endif
else {
std::cerr << "Error: Cannot add object. Type is unknown!" << std::endl;
}
}
......@@ -89,11 +153,37 @@ TriMesh* OBJImporter::currentTriMesh(){
//-----------------------------------------------------------------------------
#ifdef ENABLE_BSPLINECURVE_SUPPORT
BSplineCurve* OBJImporter::currentCurve(){
if (curves_.size() == 0)
return 0;
else
return curves_.back();
}
#endif
//-----------------------------------------------------------------------------
#ifdef ENABLE_BSPLINESURFACE_SUPPORT
BSplineSurface* OBJImporter::currentSurface(){
if (surfaces_.size() == 0)
return 0;
else
return surfaces_.back();
}
#endif
//-----------------------------------------------------------------------------
/// check if the vertex of a face is already added to the mesh. if not add it.
void OBJImporter::checkExistance(VertexHandle _vh){
if ( isTriangleMesh( currentObject() ) ){
//handle triangle meshes
if ( !currentTriMesh() ) return;
......@@ -110,7 +200,7 @@ void OBJImporter::checkExistance(VertexHandle _vh){
//handle poly meshes
if ( !currentPolyMesh() ) return;
if ( _vh >= (int)vertices_.size() ){
std::cerr << "Error: Vertex ID too large" << std::endl;
return;
......@@ -217,7 +307,7 @@ void OBJImporter::addFace(const VHandles& _indices){
vertices.push_back( vertexMapTri_[ _indices[i] ] );
}else{
std::cerr << "Error: cannot add face. undefined index." << std::endl;
std::cerr << "Error: cannot add face. undefined index (" << _indices[i] << ")" << std::endl;
return;
}
}
......@@ -239,13 +329,13 @@ void OBJImporter::addFace(const VHandles& _indices){
std::vector< PolyMesh::VertexHandle > vertices;
for (uint i=0; i < _indices.size(); i++){
if ( vertexMapPoly_.find( _indices[i] ) != vertexMapPoly_.end() ){
vertices.push_back( vertexMapPoly_[ _indices[i] ] );
}else{
std::cerr << "Error: cannot add face. undefined index." << std::endl;
std::cerr << "Error: cannot add face. undefined index (" << _indices[i] << ")" << std::endl;
return;
}
}
......@@ -277,7 +367,7 @@ void OBJImporter::addFace(const VHandles& _indices, const std::vector<int>& _fac
vertices.push_back( vertexMapTri_[ _indices[i] ] );
}else{
std::cerr << "Error: cannot add face. undefined index." << std::endl;
std::cerr << "Error: cannot add face. undefined index (" << _indices[i] << ")" << std::endl;
return;
}
}
......@@ -503,6 +593,18 @@ bool OBJImporter::isPolyMesh(int _objectID){
//-----------------------------------------------------------------------------
bool OBJImporter::isCurve(int _objectID){
return objectOptions_[ _objectID ] & CURVE;
}
//-----------------------------------------------------------------------------
bool OBJImporter::isSurface(int _objectID){
return objectOptions_[ _objectID ] & SURFACE;
}
//-----------------------------------------------------------------------------
bool OBJImporter::hasNormals(int _objectID){
return objectOptions_[ _objectID ] & NORMALS;
......
......@@ -57,6 +57,15 @@
#include <ObjectTypes/TriangleMesh/TriangleMesh.hh>
#include <OpenFlipper/common/BaseObject.hh>
#ifdef ENABLE_BSPLINECURVE_SUPPORT
#include <ObjectTypes/BSplineCurve/BSplineCurve.hh>
#endif
#ifdef ENABLE_BSPLINESURFACE_SUPPORT
#include <ObjectTypes/BSplineSurface/BSplineSurface.hh>
#endif
#include "Material.hh"
//=== IMPLEMENTATION ==========================================================
......@@ -80,13 +89,15 @@ class OBJImporter
NONE = 0,
TRIMESH = 1,
POLYMESH = 1 << 1,
NORMALS = 1 << 2,
TEXCOORDS = 1 << 3,
FACECOLOR = 1 << 4,
TEXTURE = 1 << 5,
FORCE_NOCOLOR = 1 << 6,
FORCE_NONORMALS = 1 << 7,
FORCE_NOTEXTURES = 1 << 8
CURVE = 1 << 2,
SURFACE = 1 << 3,
NORMALS = 1 << 4,
TEXCOORDS = 1 << 5,
FACECOLOR = 1 << 6,
TEXTURE = 1 << 7,
FORCE_NOCOLOR = 1 << 8,
FORCE_NONORMALS = 1 << 9,
FORCE_NOTEXTURES = 1 << 10
};
typedef uint ObjectOptions;
......@@ -97,12 +108,23 @@ class OBJImporter
/// add a vertex with coordinate \c _point
VertexHandle addVertex(const Vec3f& _point);
/// get vertex with given index
Vec3f vertex(uint _index);
/// add texture coordinates
int addTexCoord(const Vec2f& _coord);
/// add a normal
int addNormal(const Vec3f& _normal);
/// set degree
void setDegreeU(int _degree);
void setDegreeV(int _degree);
/// get current degree
int degreeU();
int degreeV();
/// add an object
void addObject( BaseObject* _object );
......@@ -115,6 +137,14 @@ class OBJImporter
/// get a pointer to the active triMesh
TriMesh* currentTriMesh();
#ifdef ENABLE_BSPLINECURVE_SUPPORT
BSplineCurve* currentCurve();
#endif
#ifdef ENABLE_BSPLINECURVE_SUPPORT
BSplineSurface* currentSurface();
#endif
/// check if the vertex of a face is already added to the mesh. if not add it.
void checkExistance(VertexHandle _vh);
......@@ -139,6 +169,8 @@ class OBJImporter
bool hasTextureCoords(int _objectID);
bool isTriangleMesh(int _objectID);
bool isPolyMesh(int _objectID);
bool isCurve(int _objectID);
bool isSurface(int _objectID);
/// Global Properties
uint n_vertices();
......@@ -189,6 +221,9 @@ class OBJImporter
std::vector< Vec3f > normals_;
std::vector< Vec2f > texCoords_;
int degreeU_;
int degreeV_;
MaterialList materials_;
QString path_;
......@@ -208,6 +243,14 @@ class OBJImporter
std::vector< TriMesh* > triMeshes_;
#ifdef ENABLE_BSPLINECURVE_SUPPORT
std::vector< BSplineCurve* > curves_;
#endif
#ifdef ENABLE_BSPLINESURFACE_SUPPORT
std::vector< BSplineSurface* > surfaces_;
#endif
//object data
std::vector< BaseObject* > objects_;
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