Commit 625300c0 authored by Isaak Lim's avatar Isaak Lim
Browse files

- added precision option for the OpenFlipper FileInterface

- implemented precision option for File plugins where possible
- omitted OpenVolumeMesh implementation for now

refs #1157

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@15657 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 04290b9c
...@@ -245,7 +245,7 @@ add_point(const Point& _p) ...@@ -245,7 +245,7 @@ add_point(const Point& _p)
// add available properties // add available properties
if( vertex_normals_available() ) if( vertex_normals_available() )
vnormals_.push_back( Point(0,0,0)); vnormals_.push_back( Point(0,0,0));
if( vertex_binormals_available() ) if( vertex_binormals_available() )
vbinormals_.push_back( Point(0,0,0)); vbinormals_.push_back( Point(0,0,0));
...@@ -288,14 +288,14 @@ PolyLineT<PointT>:: ...@@ -288,14 +288,14 @@ PolyLineT<PointT>::
insert_point(int _idx, const Point& _p) insert_point(int _idx, const Point& _p)
{ {
assert(_idx < (int)n_vertices() ); assert(_idx < (int)n_vertices() );
// insert new point // insert new point
points_.insert(points_.begin()+_idx, _p); points_.insert(points_.begin()+_idx, _p);
// insert available properties // insert available properties
if( vertex_normals_available() ) if( vertex_normals_available() )
vnormals_.insert(vnormals_.begin()+_idx, Point(0,0,0)); vnormals_.insert(vnormals_.begin()+_idx, Point(0,0,0));
if( vertex_binormals_available() ) if( vertex_binormals_available() )
vbinormals_.insert(vbinormals_.begin()+_idx, Point(0,0,0)); vbinormals_.insert(vbinormals_.begin()+_idx, Point(0,0,0));
...@@ -332,7 +332,7 @@ insert_point(int _idx, const Point& _p) ...@@ -332,7 +332,7 @@ insert_point(int _idx, const Point& _p)
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
template <class PointT> template <class PointT>
void void
...@@ -348,7 +348,7 @@ delete_point(int _idx) ...@@ -348,7 +348,7 @@ delete_point(int _idx)
// delete available properties // delete available properties
if( vertex_normals_available() ) if( vertex_normals_available() )
vnormals_.erase(vnormals_.begin()+_idx); vnormals_.erase(vnormals_.begin()+_idx);
if( vertex_binormals_available() ) if( vertex_binormals_available() )
vbinormals_.erase(vbinormals_.begin()+_idx); vbinormals_.erase(vbinormals_.begin()+_idx);
...@@ -1029,7 +1029,7 @@ load(const char* _filename) ...@@ -1029,7 +1029,7 @@ load(const char* _filename)
} }
else if(token == "VEHANDLES") else if(token == "VEHANDLES")
{ {
if(!vertex_ehandles_available()) request_vertex_ehandles(); if(!vertex_ehandles_available()) request_vertex_ehandles();
for(unsigned int i=0; i<n_vertices(); ++i) for(unsigned int i=0; i<n_vertices(); ++i)
fin >> vertex_ehandle(i); fin >> vertex_ehandle(i);
} }
...@@ -1071,10 +1071,12 @@ load(const char* _filename) ...@@ -1071,10 +1071,12 @@ load(const char* _filename)
template <class PointT> template <class PointT>
void void
PolyLineT<PointT>:: PolyLineT<PointT>::
save(const char* _filename) const save(const char* _filename, std::streamsize _precision) const
{ {
std::ofstream fout(_filename, std::ios::out); std::ofstream fout(_filename, std::ios::out);
fout.precision(_precision);
// is polyline closed? // is polyline closed?
fout << closed_ << std::endl; fout << closed_ << std::endl;
...@@ -1117,7 +1119,7 @@ save(const char* _filename) const ...@@ -1117,7 +1119,7 @@ save(const char* _filename) const
for( unsigned int i=0; i<n_vertices(); ++i) for( unsigned int i=0; i<n_vertices(); ++i)
fout << vertex_fhandle(i) << std::endl; fout << vertex_fhandle(i) << std::endl;
} }
if(vertex_normals_available()) if(vertex_normals_available())
{ {
fout << "VNORMALS" << std::endl; fout << "VNORMALS" << std::endl;
...@@ -1128,7 +1130,7 @@ save(const char* _filename) const ...@@ -1128,7 +1130,7 @@ save(const char* _filename) const
fout << vnormals_[i][2] << std::endl; fout << vnormals_[i][2] << std::endl;
} }
} }
if(vertex_binormals_available()) if(vertex_binormals_available())
{ {
fout << "VBINORMALS" << std::endl; fout << "VBINORMALS" << std::endl;
...@@ -1206,7 +1208,7 @@ copy_vertex_complete(const PolyLineT<PointT>& _pl, unsigned int _i, unsigned int ...@@ -1206,7 +1208,7 @@ copy_vertex_complete(const PolyLineT<PointT>& _pl, unsigned int _i, unsigned int
if( _pl.vertex_normals_available()) if( _pl.vertex_normals_available())
if( vertex_normals_available()) if( vertex_normals_available())
vertex_normal(_j) = _pl.vertex_normal(_i); vertex_normal(_j) = _pl.vertex_normal(_i);
if( _pl.vertex_binormals_available()) if( _pl.vertex_binormals_available())
if( vertex_binormals_available()) if( vertex_binormals_available())
vertex_binormal(_j) = _pl.vertex_binormal(_i); vertex_binormal(_j) = _pl.vertex_binormal(_i);
......
...@@ -160,7 +160,7 @@ public: ...@@ -160,7 +160,7 @@ public:
const Point& back() const { return points_[n_vertices()-1];} const Point& back() const { return points_[n_vertices()-1];}
/// \brief get the i-th oriented edge vector /// \brief get the i-th oriented edge vector
Point edge_vector(unsigned int _i) const Point edge_vector(unsigned int _i) const
{ return(point((_i+1)%n_vertices())-point(_i));} { return(point((_i+1)%n_vertices())-point(_i));}
/** \brief Compute the length of the polyline (in future cached method) /** \brief Compute the length of the polyline (in future cached method)
...@@ -289,7 +289,7 @@ public: ...@@ -289,7 +289,7 @@ public:
void load( const char* _filename); void load( const char* _filename);
/// \brief Save polyline to a file /// \brief Save polyline to a file
void save( const char* _filename) const; void save( const char* _filename, std::streamsize _precision = 6) const;
// ############################### Standard Property Handling ############################# // ############################### Standard Property Handling #############################
...@@ -341,7 +341,7 @@ public: ...@@ -341,7 +341,7 @@ public:
// property access ( no range or availability check! ) // property access ( no range or availability check! )
Point& vertex_normal(unsigned int _i) { return vnormals_[_i];} Point& vertex_normal(unsigned int _i) { return vnormals_[_i];}
const Point& vertex_normal(unsigned int _i) const { return vnormals_[_i];} const Point& vertex_normal(unsigned int _i) const { return vnormals_[_i];}
Point& vertex_binormal(unsigned int _i) { return vbinormals_[_i];} Point& vertex_binormal(unsigned int _i) { return vbinormals_[_i];}
const Point& vertex_binormal(unsigned int _i) const { return vbinormals_[_i];} const Point& vertex_binormal(unsigned int _i) const { return vbinormals_[_i];}
...@@ -376,13 +376,13 @@ public: ...@@ -376,13 +376,13 @@ public:
const unsigned char& edge_selection(unsigned int _i) const {return eselections_[_i];} const unsigned char& edge_selection(unsigned int _i) const {return eselections_[_i];}
// ############################### SelectionWrappers ############################ // ############################### SelectionWrappers ############################
bool vertex_selected(unsigned int _i) { return (_i < vselections_.size() ? vertex_selection(_i) == 1 : false); } bool vertex_selected(unsigned int _i) { return (_i < vselections_.size() ? vertex_selection(_i) == 1 : false); }
bool edge_selected(unsigned int _i) { return (_i < eselections_.size() ? edge_selection(_i) == 1 : false); } bool edge_selected(unsigned int _i) { return (_i < eselections_.size() ? edge_selection(_i) == 1 : false); }
void select_vertex(unsigned int _i) { if(_i < vselections_.size()) vertex_selection(_i) = 1; } void select_vertex(unsigned int _i) { if(_i < vselections_.size()) vertex_selection(_i) = 1; }
void select_edge(unsigned int _i) { if(_i < eselections_.size()) edge_selection(_i) = 1; } void select_edge(unsigned int _i) { if(_i < eselections_.size()) edge_selection(_i) = 1; }
void deselect_vertex(unsigned int _i) { if(_i < vselections_.size()) vertex_selection(_i) = 0; } void deselect_vertex(unsigned int _i) { if(_i < vselections_.size()) vertex_selection(_i) = 0; }
void deselect_edge(unsigned int _i) { if(_i < eselections_.size()) edge_selection(_i) = 0; } void deselect_edge(unsigned int _i) { if(_i < eselections_.size()) edge_selection(_i) = 0; }
......
...@@ -70,7 +70,7 @@ class FileInterface { ...@@ -70,7 +70,7 @@ class FileInterface {
public: public:
/// Destructor /// Destructor
virtual ~FileInterface() {}; virtual ~FileInterface() {};
/** You can provide a special widget showing options for saving your file types /** You can provide a special widget showing options for saving your file types
* depending on the current filter * depending on the current filter
...@@ -184,7 +184,7 @@ public slots: ...@@ -184,7 +184,7 @@ public slots:
* provided dataTypes ( see supportedType ). * provided dataTypes ( see supportedType ).
* Additionally to the filename you get the id of the object to save * Additionally to the filename you get the id of the object to save
*/ */
virtual bool saveObject(int _id, QString _filename) = 0; virtual bool saveObject(int _id, QString _filename, std::streamsize _precision = 6) = 0;
/** \brief Save multiple objects to one file /** \brief Save multiple objects to one file
* *
......
...@@ -146,34 +146,34 @@ void trimString( std::string& _string) { ...@@ -146,34 +146,34 @@ void trimString( std::string& _string) {
//----------------------------------------------------------------------------------------------------- //-----------------------------------------------------------------------------------------------------
int FileBVHPlugin::loadObject(QString _filename) { int FileBVHPlugin::loadObject(QString _filename) {
if ( checkJointScaling_ != 0 ) if ( checkJointScaling_ != 0 )
ignoreJointScaling_ = checkJointScaling_->isChecked(); ignoreJointScaling_ = checkJointScaling_->isChecked();
else else
ignoreJointScaling_ = OpenFlipperSettings().value("FileBVH/Load/JointScaling",true).toBool(); ignoreJointScaling_ = OpenFlipperSettings().value("FileBVH/Load/JointScaling",true).toBool();
//setup filestream //setup filestream
std::fstream input( _filename.toUtf8(), std::ios_base::in ); std::fstream input( _filename.toUtf8(), std::ios_base::in );
if ( !input.is_open() || !input.good() ){ if ( !input.is_open() || !input.good() ){
emit log(LOGERR, tr("Error: cannot open file %1").arg(_filename) ); emit log(LOGERR, tr("Error: cannot open file %1").arg(_filename) );
return -1; return -1;
} }
//add a skeleton //add a skeleton
int id = -1; int id = -1;
emit addEmptyObject(DATA_SKELETON, id); emit addEmptyObject(DATA_SKELETON, id);
BaseObjectData* object = 0; BaseObjectData* object = 0;
Skeleton* skeleton = 0; Skeleton* skeleton = 0;
if(PluginFunctions::getObject( id, object)){ if(PluginFunctions::getObject( id, object)){
skeleton = PluginFunctions::skeleton( object ); skeleton = PluginFunctions::skeleton( object );
object->setFromFileName(_filename); object->setFromFileName(_filename);
object->setName(object->filename()); object->setName(object->filename());
} }
if (skeleton == 0){ if (skeleton == 0){
emit log(LOGERR, tr("Error: Unable to add skeleton!")); emit log(LOGERR, tr("Error: Unable to add skeleton!"));
return -1; return -1;
...@@ -181,20 +181,20 @@ int FileBVHPlugin::loadObject(QString _filename) { ...@@ -181,20 +181,20 @@ int FileBVHPlugin::loadObject(QString _filename) {
Skeleton::Joint* currentParent = 0; Skeleton::Joint* currentParent = 0;
Skeleton::Pose* refPose = skeleton->referencePose(); Skeleton::Pose* refPose = skeleton->referencePose();
std::string line; std::string line;
std::string keyWrd; std::string keyWrd;
std::bitset<4> waitingFor = HIERARCHY; std::bitset<4> waitingFor = HIERARCHY;
std::map< Skeleton::Joint* , JointInfo> jointInfos; std::map< Skeleton::Joint* , JointInfo> jointInfos;
uint dataOffset = 0; //Offset of the current channel in the frame data uint dataOffset = 0; //Offset of the current channel in the frame data
AnimationHandle animHandle; AnimationHandle animHandle;
uint currentFrame = 0; uint currentFrame = 0;
uint frameCount = 0; uint frameCount = 0;
while( input && !input.eof() ) while( input && !input.eof() )
{ {
std::getline(input,line); std::getline(input,line);
...@@ -205,7 +205,7 @@ int FileBVHPlugin::loadObject(QString _filename) { ...@@ -205,7 +205,7 @@ int FileBVHPlugin::loadObject(QString _filename) {
// Trim Both leading and trailing spaces // Trim Both leading and trailing spaces
trimString(line); trimString(line);
// ignore empty lines // ignore empty lines
if ( line.size() == 0 ) if ( line.size() == 0 )
continue; continue;
...@@ -220,10 +220,10 @@ int FileBVHPlugin::loadObject(QString _filename) { ...@@ -220,10 +220,10 @@ int FileBVHPlugin::loadObject(QString _filename) {
waitingFor = ROOT_DEFINITION; waitingFor = ROOT_DEFINITION;
continue; continue;
} }
//ROOT_DEFINITION //ROOT_DEFINITION
if ( (waitingFor == ROOT_DEFINITION) && (keyWrd == "ROOT") ){ if ( (waitingFor == ROOT_DEFINITION) && (keyWrd == "ROOT") ){
std::string name; std::string name;
stream >> name; stream >> name;
...@@ -236,7 +236,7 @@ int FileBVHPlugin::loadObject(QString _filename) { ...@@ -236,7 +236,7 @@ int FileBVHPlugin::loadObject(QString _filename) {
waitingFor = OPENED_BRACKET; waitingFor = OPENED_BRACKET;
continue; continue;
} }
//OPENED_BRACKET //OPENED_BRACKET
if ( (waitingFor == OPENED_BRACKET) && (keyWrd == "{") ){ if ( (waitingFor == OPENED_BRACKET) && (keyWrd == "{") ){
...@@ -257,23 +257,23 @@ int FileBVHPlugin::loadObject(QString _filename) { ...@@ -257,23 +257,23 @@ int FileBVHPlugin::loadObject(QString _filename) {
currentParent = currentParent->parent(); currentParent = currentParent->parent();
continue; continue;
} }
//JOINT //JOINT
if ( (!(waitingFor&JOINT).none()) && (keyWrd == "JOINT") ){ if ( (!(waitingFor&JOINT).none()) && (keyWrd == "JOINT") ){
std::string name; std::string name;
stream >> name; stream >> name;
Skeleton::Joint* newJoint = new Skeleton::Joint(currentParent, name); Skeleton::Joint* newJoint = new Skeleton::Joint(currentParent, name);
skeleton->addJoint(currentParent, newJoint); skeleton->addJoint(currentParent, newJoint);
JointInfo info; //we found a new Joint, hence we need an ne JointInfo to store the channel inforamtions. JointInfo info; //we found a new Joint, hence we need an ne JointInfo to store the channel inforamtions.
jointInfos[newJoint]=info; //store Joint info for later use in case of CHANNELS jointInfos[newJoint]=info; //store Joint info for later use in case of CHANNELS
currentParent = newJoint; currentParent = newJoint;
waitingFor = OPENED_BRACKET; waitingFor = OPENED_BRACKET;
continue; continue;
} }
//OFFSET //OFFSET
if ( (!(waitingFor&OFFSET).none()) && (keyWrd == "OFFSET") ){ if ( (!(waitingFor&OFFSET).none()) && (keyWrd == "OFFSET") ){
...@@ -282,18 +282,18 @@ int FileBVHPlugin::loadObject(QString _filename) { ...@@ -282,18 +282,18 @@ int FileBVHPlugin::loadObject(QString _filename) {
stream >> translation[0]; stream >> translation[0];
stream >> translation[1]; stream >> translation[1];
stream >> translation[2]; stream >> translation[2];
refPose->setLocalTranslation(currentParent->id(), translation ); refPose->setLocalTranslation(currentParent->id(), translation );
continue; continue;
} }
//CHANNELS //CHANNELS
if ( (!(waitingFor&CHANNELS).none()) && (keyWrd == "CHANNELS") ){ if ( (!(waitingFor&CHANNELS).none()) && (keyWrd == "CHANNELS") ){
uint channelCount; uint channelCount;
stream >> channelCount; stream >> channelCount;
JointInfo& info=jointInfos[ currentParent ]; JointInfo& info=jointInfos[ currentParent ];
if(channelCount>6) //well somethings wrong here... if(channelCount>6) //well somethings wrong here...
...@@ -316,9 +316,9 @@ int FileBVHPlugin::loadObject(QString _filename) { ...@@ -316,9 +316,9 @@ int FileBVHPlugin::loadObject(QString _filename) {
info.dataChannels[info.channelOffset]=YR; info.dataChannels[info.channelOffset]=YR;
else if (channelType == "Zrotation") else if (channelType == "Zrotation")
info.dataChannels[info.channelOffset]=ZR; info.dataChannels[info.channelOffset]=ZR;
else else
{std::cerr << "Error: Unknown channelType. Ignoring." << std::endl;} {std::cerr << "Error: Unknown channelType. Ignoring." << std::endl;}
if(info.dataChannels[info.channelOffset]!=NotGiven){ //if there is a channel assigned if(info.dataChannels[info.channelOffset]!=NotGiven){ //if there is a channel assigned
info.dataOffset[info.channelOffset]=dataOffset; //the value for this channel will be found this data position info.dataOffset[info.channelOffset]=dataOffset; //the value for this channel will be found this data position
info.channelOffset++; //write next info into the next index info.channelOffset++; //write next info into the next index
...@@ -327,7 +327,7 @@ int FileBVHPlugin::loadObject(QString _filename) { ...@@ -327,7 +327,7 @@ int FileBVHPlugin::loadObject(QString _filename) {
} }
continue; continue;
} }
// ENDSITE // ENDSITE
if ( (!(waitingFor&ENDSITE).none()) && (keyWrd == "End") ){ if ( (!(waitingFor&ENDSITE).none()) && (keyWrd == "End") ){
...@@ -335,38 +335,38 @@ int FileBVHPlugin::loadObject(QString _filename) { ...@@ -335,38 +335,38 @@ int FileBVHPlugin::loadObject(QString _filename) {
stream >> site; stream >> site;
std::string name = "End"; std::string name = "End";
Skeleton::Joint* newJoint = new Skeleton::Joint(currentParent, currentParent->name() + name); Skeleton::Joint* newJoint = new Skeleton::Joint(currentParent, currentParent->name() + name);
skeleton->addJoint(currentParent, newJoint); skeleton->addJoint(currentParent, newJoint);
currentParent = newJoint; currentParent = newJoint;
waitingFor = OPENED_BRACKET; waitingFor = OPENED_BRACKET;
continue; continue;
} }
//MOTION //MOTION
if ( (waitingFor == MOTION) && (keyWrd == "MOTION") ){ if ( (waitingFor == MOTION) && (keyWrd == "MOTION") ){
waitingFor = FRAMES; waitingFor = FRAMES;
continue; continue;
} }
//Frames //Frames
if ( (waitingFor == FRAMES) && (keyWrd == "Frames:") ){ if ( (waitingFor == FRAMES) && (keyWrd == "Frames:") ){
stream >> frameCount; stream >> frameCount;
if (frameCount > 0){ if (frameCount > 0){
FrameAnimationT<ACG::Vec3d>* animation = new FrameAnimationT<ACG::Vec3d>(skeleton, frameCount); FrameAnimationT<ACG::Vec3d>* animation = new FrameAnimationT<ACG::Vec3d>(skeleton, frameCount);
animHandle = skeleton->addAnimation(object->filename().toStdString(), animation); animHandle = skeleton->addAnimation(object->filename().toStdString(), animation);
} }
waitingFor = FRAME_TIME; waitingFor = FRAME_TIME;
continue; continue;
} }
//Frame Time //Frame Time
if ( (waitingFor == FRAME_TIME) && (keyWrd == "Frame") ){ if ( (waitingFor == FRAME_TIME) && (keyWrd == "Frame") ){
std::string time; std::string time;
stream >> time; stream >> time;
...@@ -382,12 +382,12 @@ int FileBVHPlugin::loadObject(QString _filename) { ...@@ -382,12 +382,12 @@ int FileBVHPlugin::loadObject(QString _filename) {
//Channel Data //Channel Data
if ( (waitingFor == CHANNEL_DATA) ){ if ( (waitingFor == CHANNEL_DATA) ){
// a vector to store all the data for this frame // a vector to store all the data for this frame
std::vector<double> data(dataOffset,0.0); std::vector<double> data(dataOffset,0.0);
Skeleton::Pose* pose = 0; Skeleton::Pose* pose = 0;
if ( currentFrame < frameCount ){ if ( currentFrame < frameCount ){
animHandle.setFrame( currentFrame ); animHandle.setFrame( currentFrame );
pose = skeleton->pose(animHandle); pose = skeleton->pose(animHandle);
...@@ -408,9 +408,9 @@ int FileBVHPlugin::loadObject(QString _filename) { ...@@ -408,9 +408,9 @@ int FileBVHPlugin::loadObject(QString _filename) {
if ( currentFrame < frameCount ) if ( currentFrame < frameCount )
for (unsigned long jointID=0; jointID < skeleton->jointCount(); jointID++ ){ for (unsigned long jointID=0; jointID < skeleton->jointCount(); jointID++ ){
Skeleton::Joint* joint = skeleton->joint( jointID ); Skeleton::Joint* joint = skeleton->joint( jointID );
// special case: end-effector joints // special case: end-effector joints
// they don't have animation data // they don't have animation data
if ( jointInfos.find(joint) == jointInfos.end() ){ if ( jointInfos.find(joint) == jointInfos.end() ){
...@@ -420,7 +420,7 @@ int FileBVHPlugin::loadObject(QString _filename) { ...@@ -420,7 +420,7 @@ int FileBVHPlugin::loadObject(QString _filename) {
} }
JointInfo& info=jointInfos[joint]; //get the cahnnels info for the current joint JointInfo& info=jointInfos[joint]; //get the cahnnels info for the current joint
ACG::Vec3d translation(0.0,0.0,0.0); //setup translation ACG::Vec3d translation(0.0,0.0,0.0); //setup translation
ACG::GLMatrixd matRot; //setup rotation ACG::GLMatrixd matRot; //setup rotation
...@@ -431,7 +431,7 @@ int FileBVHPlugin::loadObject(QString _filename) { ...@@ -431,7 +431,7 @@ int FileBVHPlugin::loadObject(QString _filename) {