Commit 9bf2c65d authored by Jan Möbius's avatar Jan Möbius
Browse files

Save function moved into file polyline plugin

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@17369 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 4dcb0e33
......@@ -4,8 +4,6 @@
#include <QtGui>
#endif
#include <QFileInfo>
#include "FilePolyLine.hh"
#include <iostream>
......@@ -18,6 +16,168 @@
#include <OpenFlipper/ACGHelper/DrawModeConverter.hh>
//-----------------------------------------------------------------------------
template <class PointT>
void loadPolyLine(ACG::PolyLineT<PointT>& _polyLine, const char* _filename)
{
// clear old polyline
_polyLine.clear();
std::ifstream fin(_filename, std::ios::in);
// closed ?
bool closed = false;
fin >> closed;
_polyLine.set_closed(closed);
// number of points
int num_points;
fin >> num_points;
// read points
for(int i=0; i<num_points; ++i)
{
typename PointT::value_type x,y,z;
fin >> x;
fin >> y;
fin >> z;
PointT p(x,y,z);
_polyLine.add_point(p);
}
// ###########################
// READ properties
std::string token;
while(true)
{
token = "-";
fin >> token;
if(token == "VVHANDLES")
{
if(!_polyLine.vertex_vhandles_available()) _polyLine.request_vertex_vhandles();
for(unsigned int i=0; i<_polyLine.n_vertices(); ++i)
fin >> _polyLine.vertex_vhandle(i);
}
else if(token == "VEHANDLES")
{
if(!_polyLine.vertex_ehandles_available()) _polyLine.request_vertex_ehandles();
for(unsigned int i=0; i<_polyLine.n_vertices(); ++i)
fin >> _polyLine.vertex_ehandle(i);
}
else if(token == "VFHANDLES")
{
if(!_polyLine.vertex_fhandles_available()) _polyLine.request_vertex_fhandles();
for(unsigned int i=0; i<_polyLine.n_vertices(); ++i)
fin >> _polyLine.vertex_fhandle(i);
}
else if(token == "VNORMALS")
{
if(!_polyLine.vertex_normals_available()) _polyLine.request_vertex_normals();
for(unsigned int i=0; i<_polyLine.n_vertices(); ++i)
{
fin >> _polyLine.vertex_normal(i)[0];
fin >> _polyLine.vertex_normal(i)[1];
fin >> _polyLine.vertex_normal(i)[2];
}
}
else if(token == "VBINORMALS")
{
if(!_polyLine.vertex_binormals_available()) _polyLine.request_vertex_binormals();
for(unsigned int i=0; i<_polyLine.n_vertices(); ++i)
{
fin >> _polyLine.vertex_binormal(i)[0];
fin >> _polyLine.vertex_binormal(i)[1];
fin >> _polyLine.vertex_binormal(i)[2];
}
}
else if(token != "") break; //eat up empty lines
}
fin.close();
}
template <class PointT>
void savePolyLine(ACG::PolyLineT<PointT>& _polyLine, const char* _filename)
{
std::ofstream fout(_filename, std::ios::out);
// is polyline closed?
fout << _polyLine.is_closed() << std::endl;
// number of points
fout << _polyLine.n_vertices() << std::endl;
std::cerr << "write " << _filename << std::endl;
std::cerr << "#points: " << _polyLine.n_vertices() << std::endl;
// write each point
for(unsigned int i=0; i< _polyLine.n_vertices(); ++i)
{
const PointT& current_point = _polyLine.point(i);
fout << current_point[0] << " ";
fout << current_point[1] << " ";
fout << current_point[2] << std::endl;
}
// ###########################
// Write properties
if(_polyLine.vertex_vhandles_available())
{
fout << "VVHANDLES" << std::endl;
for( unsigned int i=0; i<_polyLine.n_vertices(); ++i)
fout << _polyLine.vertex_vhandle(i) << std::endl;
}
if(_polyLine.vertex_ehandles_available())
{
fout << "VEHANDLES" << std::endl;
for( unsigned int i=0; i<_polyLine.n_vertices(); ++i)
fout << _polyLine.vertex_ehandle(i) << std::endl;
}
if(_polyLine.vertex_fhandles_available())
{
fout << "VFHANDLES" << std::endl;
for( unsigned int i=0; i<_polyLine.n_vertices(); ++i)
fout << _polyLine.vertex_fhandle(i) << std::endl;
}
if(_polyLine.vertex_normals_available())
{
fout << "VNORMALS" << std::endl;
for( unsigned int i=0; i<_polyLine.n_vertices(); ++i)
{
const PointT& current_vnormal = _polyLine.vertex_normal(i);
fout << current_vnormal[0] << " ";
fout << current_vnormal[1] << " ";
fout << current_vnormal[2] << std::endl;
}
}
if(_polyLine.vertex_binormals_available())
{
fout << "VBINORMALS" << std::endl;
for( unsigned int i=0; i<_polyLine.n_vertices(); ++i)
{
const PointT& current_bnormal = _polyLine.vertex_binormal(i);
fout << current_bnormal[0] << " ";
fout << current_bnormal[1] << " ";
fout << current_bnormal[2] << std::endl;
}
}
fout.close();
}
void FilePolyLinePlugin::initializePlugin() {
// Data type has already been added by polyline type plugin
}
......@@ -43,7 +203,7 @@ int FilePolyLinePlugin::loadObject(QString _filename)
PolyLineObject* pol(0);
if(PluginFunctions::getObject( id, pol))
{
pol->line()->load(_filename.toLatin1());
loadPolyLine(*(pol->line()), _filename.toLatin1());
pol->setFromFileName(_filename);
......@@ -69,7 +229,7 @@ bool FilePolyLinePlugin::saveObject(int _id, QString _filename)
obj->setName(_filename.section(OpenFlipper::Options::dirSeparator(),-1));
obj->setPath(_filename.section(OpenFlipper::Options::dirSeparator(),0,-2) );
pol->line()->save((const char*) _filename.toLatin1());
savePolyLine(*(pol->line()), _filename.toLatin1());
}
}
......
Markdown is supported
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