Commit c58a1c44 authored by Jan Möbius's avatar Jan Möbius

Poco Finder

New PolyLine serializer


git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@17749 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 57da70a1
#include "PolyLineObjectSerializer.hh"
#include <limits>
#include <ObjectTypes/PolyLine/PolyLineCircleData.hh>
#include <ObjectTypes/PolyLine/PolyLineBezierSplineData.hh>
PolyLineObjectSerializer::PolyLineObjectSerializer(PolyLineObject* _object)
: instance(_object)
{
}
void PolyLineObjectSerializer::serialize(std::ostream& _stream) {
std::ostream& fout = _stream;
PolyLine& _polyLine = *instance->line();
// 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 PolyLine::Point& current_point = _polyLine.point(i);
fout << current_point[0] << " ";
fout << current_point[1] << " ";
fout << current_point[2] << std::endl;
}
// ###########################
// Write properties(unsigned int)CircleType
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 PolyLine::Point& 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 PolyLine::Point& current_bnormal = _polyLine.vertex_binormal(i);
fout << current_bnormal[0] << " ";
fout << current_bnormal[1] << " ";
fout << current_bnormal[2] << std::endl;
}
}
PolyLineCircleData* circleData = dynamic_cast<PolyLineCircleData*>(instance->objectData(CIRCLE_DATA));
if(circleData) {
fout << "CIRCLEDATA" << std::endl;
fout << circleData->circleCenter_ << std::endl;
fout << circleData->circleMainAxis_ << std::endl;
fout << circleData->circleMainRadius_ << std::endl;
fout << circleData->circleNormal_ << std::endl;
fout << circleData->circleSideAxis_ << std::endl;
fout << circleData->circleSideRadius_ << std::endl;
}
PolyLineBezierSplineData* splineData = dynamic_cast<PolyLineBezierSplineData*>(instance->objectData(BEZSPLINE_DATA));
if(splineData) {
fout << "SPLINEDATA" << std::endl;
fout << (unsigned int)splineData->points_.size() << std::endl;
for(unsigned int i = 0; i < splineData->points_.size(); i++) {
fout << splineData->points_[i].normal << std::endl;
fout << splineData->points_[i].position << std::endl;
}
fout << (unsigned int)splineData->handles_.size() << std::endl;
for(unsigned int i = 0; i < splineData->handles_.size(); i++)
fout << splineData->handles_[i] << std::endl;
fout << std::endl;
}
}
void PolyLineObjectSerializer::deserialize(std::istream& _stream) {
std::istream& fin = _stream;
PolyLine& _polyLine = *instance->line();
// clear old polyline
_polyLine.clear();
// 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)
{
PolyLine::Point::value_type x,y,z;
fin >> x;
fin >> y;
fin >> z;
PolyLine::Point 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 == "CIRCLEDATA") {
ACG::Vec3d center, normal, main, side;
double rmain, rside;
fin >> center;
fin >> main;
fin >> rmain;
fin >> normal;
fin >> side;
fin >> rside;
PolyLineCircleData* circleData = new PolyLineCircleData(center,normal,main,side,rmain,rside,std::numeric_limits<unsigned int>::max());
instance->setObjectData(CIRCLE_DATA, circleData);
}
else if(token == "SPLINEDATA") {
PolyLineBezierSplineData* splineData = new PolyLineBezierSplineData(std::numeric_limits<unsigned int>::max());
unsigned int pointCount, handleCount;
fin >> pointCount;
PolyLineBezierSplineData::InterpolatePoint point;
for(unsigned int i = 0; i < pointCount; i++) {
fin >> point.normal;
fin >> point.position;
splineData->points_.push_back(point);
}
fin >> handleCount;
for(unsigned int i = 0; i < handleCount; i++) {
fin >> point.position;
splineData->handles_.push_back(point.position);
}
instance->setObjectData(BEZSPLINE_DATA, splineData);
}
else if(token != "") break; //eat up empty lines
}
}
//=============================================================================
//
// Types
//
//=============================================================================
/**
* \file PolyLineObjectSerializer.hh
* This File contains serialization routines for poly line objects
*/
#ifndef POLYLINEOBJECTSERIALIZER_HH_
#define POLYLINEOBJECTSERIALIZER_HH_
#include "PolyLineObject.hh"
//== CLASS DEFINITION =========================================================
/** This class provides the functionality for serializing PolyLineObjects including all known object data
*/
class DLLEXPORT PolyLineObjectSerializer
{
private:
PolyLineObject* instance;
public:
PolyLineObjectSerializer(PolyLineObject* _object);
void serialize(std::ostream& _stream);
void deserialize(std::istream& _stream);
};
#endif /* POLYLINEOBJECTSERIALIZER_HH_ */
......@@ -1000,8 +1000,6 @@ createCircle_createUI(int _polyLineObjectID)
lineObject->addAdditionalNode(cenNode, name(), "circle");
cenNode->drawMode(ACG::SceneGraph::DrawModes::SOLID_FLAT_SHADED);
lineObject->lineNode()->drawMode(ACG::SceneGraph::DrawModes::WIREFRAME);
emit updatedObject(lineObject->id(), UPDATE_ALL);
}
......@@ -1046,6 +1044,7 @@ me_insertCircle(QMouseEvent* _event)
PolyLineCircleData* lineData = new PolyLineCircleData(hit_point, mesh->mesh()->normal(fh), ACG::Vec3d(), ACG::Vec3d(), 0, 0, mesh->id());
newLine->setObjectData(CIRCLE_DATA, lineData);
newLine->setObjectDrawMode(ACG::SceneGraph::DrawModes::WIREFRAME);
emit updatedObject(new_line_id, UPDATE_GEOMETRY | UPDATE_TOPOLOGY);
createCircle_LastSelIndex_ = createCircle_CurrSelIndex_ = newLine->id();
......@@ -1121,7 +1120,7 @@ createSpline_createUI(int _polyLineObjectID)
handle0->enablePicking(true);
handle0->set_position(hndlPos);
lineObject->addAdditionalNode(handle0, name(), "handle", i);
handle0->drawMode(ACG::SceneGraph::DrawModes::SOLID_FLAT_SHADED);
//handle0->drawMode(ACG::SceneGraph::DrawModes::SOLID_FLAT_SHADED);
GlutLineNode* lineN;
if(lineObject->getAdditionalNode(lineN, name(), "line")) {
......@@ -1130,7 +1129,6 @@ createSpline_createUI(int _polyLineObjectID)
}
}
updatePolyBezierSpline(lineObject, tool_->sb_SplineSegNum->value());
lineObject->lineNode()->drawMode(ACG::SceneGraph::DrawModes::WIREFRAME);
emit updatedObject(createSpline_CurrSelIndex_, UPDATE_ALL);
}
......
......@@ -16,226 +16,12 @@
#include <OpenFlipper/ACGHelper/DrawModeConverter.hh>
#include <ObjectTypes/PolyLine/PolyLineCircleData.hh>
#include <ObjectTypes/PolyLine/PolyLineBezierSplineData.hh>
#include <ObjectTypes/PolyLine/PolyLineObjectSerializer.hh>
#include <OpenFlipper/BasePlugin/RPCInterface.hh>
//-----------------------------------------------------------------------------
void FilePolyLinePlugin::loadPolyLine(PolyLineObject* lineObject, const char* _filename)
{
PolyLine& _polyLine = *lineObject->line();
// 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)
{
PolyLine::Point::value_type x,y,z;
fin >> x;
fin >> y;
fin >> z;
PolyLine::Point 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 == "CIRCLEDATA") {
ACG::Vec3d center, normal, main, side;
double rmain, rside;
fin >> center;
fin >> main;
fin >> rmain;
fin >> normal;
fin >> side;
fin >> rside;
PolyLineCircleData* circleData = new PolyLineCircleData(center,normal,main,side,rmain,rside,std::numeric_limits<unsigned int>::max());
lineObject->setObjectData(CIRCLE_DATA, circleData);
}
else if(token == "SPLINEDATA") {
PolyLineBezierSplineData* splineData = new PolyLineBezierSplineData(std::numeric_limits<unsigned int>::max());
unsigned int pointCount, handleCount;
fin >> pointCount;
PolyLineBezierSplineData::InterpolatePoint point;
for(unsigned int i = 0; i < pointCount; i++) {
fin >> point.normal;
fin >> point.position;
splineData->points_.push_back(point);
}
fin >> handleCount;
for(unsigned int i = 0; i < handleCount; i++) {
fin >> point.position;
splineData->handles_.push_back(point.position);
}
lineObject->setObjectData(BEZSPLINE_DATA, splineData);
}
else if(token != "") break; //eat up empty lines
}
fin.close();
}
void FilePolyLinePlugin::savePolyLine(PolyLineObject* lineObject, const char* _filename)
{
PolyLine& _polyLine = *lineObject->line();
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 PolyLine::Point& current_point = _polyLine.point(i);
fout << current_point[0] << " ";
fout << current_point[1] << " ";
fout << current_point[2] << std::endl;
}
// ###########################
// Write properties(unsigned int)CircleType
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 PolyLine::Point& 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 PolyLine::Point& current_bnormal = _polyLine.vertex_binormal(i);
fout << current_bnormal[0] << " ";
fout << current_bnormal[1] << " ";
fout << current_bnormal[2] << std::endl;
}
}
PolyLineCircleData* circleData = dynamic_cast<PolyLineCircleData*>(lineObject->objectData(CIRCLE_DATA));
if(circleData) {
fout << "CIRCLEDATA" << std::endl;
fout << circleData->circleCenter_ << std::endl;
fout << circleData->circleMainAxis_ << std::endl;
fout << circleData->circleMainRadius_ << std::endl;
fout << circleData->circleNormal_ << std::endl;
fout << circleData->circleSideAxis_ << std::endl;
fout << circleData->circleSideRadius_ << std::endl;
}
PolyLineBezierSplineData* splineData = dynamic_cast<PolyLineBezierSplineData*>(lineObject->objectData(BEZSPLINE_DATA));
if(splineData) {
fout << "SPLINEDATA" << std::endl;
fout << (unsigned int)splineData->points_.size() << std::endl;
for(unsigned int i = 0; i < splineData->points_.size(); i++) {
fout << splineData->points_[i].normal << std::endl;
fout << splineData->points_[i].position << std::endl;
}
fout << (unsigned int)splineData->handles_.size() << std::endl;
for(unsigned int i = 0; i < splineData->handles_.size(); i++)
fout << splineData->handles_[i] << std::endl;
fout << std::endl;
}
fout.close();
}
void FilePolyLinePlugin::initializePlugin() {
// Data type has already been added by polyline type plugin
}
......@@ -261,11 +47,14 @@ int FilePolyLinePlugin::loadObject(QString _filename)
PolyLineObject* pol(0);
if(PluginFunctions::getObject( id, pol))
{
loadPolyLine(pol, _filename.toLatin1());
pol->setFromFileName(_filename);
pol->setName(QFileInfo(_filename).fileName());
std::ifstream fin(_filename.toLatin1(), std::ios::in);
PolyLineObjectSerializer serializer(pol);
serializer.deserialize(fin);
fin.close();
pol->lineNode()->drawMode(ACG::SceneGraph::DrawModes::WIREFRAME);
pol->setFromFileName(_filename);
pol->setName(QFileInfo(_filename).fileName());
}
emit openedFile( pol->id() );
......@@ -287,7 +76,10 @@ bool FilePolyLinePlugin::saveObject(int _id, QString _filename)
obj->setName(_filename.section(OpenFlipper::Options::dirSeparator(),-1));
obj->setPath(_filename.section(OpenFlipper::Options::dirSeparator(),0,-2) );
savePolyLine(pol, _filename.toLatin1());
std::ofstream fout(_filename.toLatin1(), std::ios::out);
PolyLineObjectSerializer serializer(pol);
serializer.serialize(fout);
fout.close();
}
}
......
......@@ -51,10 +51,6 @@ class FilePolyLinePlugin : public QObject, BaseInterface, FileInterface, LoadSav
void noguiSupported( ) {} ;
void initializePlugin();
void loadPolyLine(PolyLineObject* lineObject, const char* _filename);
void savePolyLine(PolyLineObject* lineObject, const char* _filename);
public :
~FilePolyLinePlugin() {};
......
......@@ -76,7 +76,7 @@ public:
void modifyFragmentEndCode(QStringList* _code)
{
_code->push_back("#ifdef SG_NORMALS");
_code->push_back("outFragment = vec4(fragNormal,1.0);");
_code->push_back("outFragment = vec4(fragNormal.x/2.0+0.5,fragNormal.y/2.0+0.5,fragNormal.z/2.0+0.5,1.0);");
_code->push_back("#endif ");
}
......
# - Find the Poco includes and libraries.
# The following variables are set if Poco is found. If Poco is not
# found, Poco_FOUND is set to false.
# Poco_FOUND - True when the Poco include directory is found.
# Poco_INCLUDE_DIRS - the path to where the poco include files are.
# Poco_LIBRARY_DIRS - The path to where the poco library files are.
# Poco_BINARY_DIRS - The path to where the poco dlls are.
# ----------------------------------------------------------------------------
# If you have installed Poco in a non-standard location.
# Then you have three options.
# In the following comments, it is assumed that <Your Path>
# points to the root directory of the include directory of Poco. e.g