48 #include <OpenFlipper/Utils/Memory/RAMInfo.hh> 50 #include <QMessageBox> 51 #include <QVBoxLayout> 54 #define TYPEAUTODETECT 0 57 #define TYPETRIANGLE 3 59 using namespace Utils;
74 savePrecisionLabel_(0),
76 saveDefaultButton_(0),
83 loadCheckManifold_(0),
84 loadDefaultButton_(0),
87 forceTriangleMesh_(false),
88 forcePolyMesh_(false),
89 readColorComp_(false),
100 userReadOptions_ |= OFFImporter::VERTEXCOLOR;
102 userReadOptions_ |= OFFImporter::FACECOLOR;
104 userReadOptions_ |= OFFImporter::COLORALPHA;
106 userReadOptions_ |= OFFImporter::VERTEXNORMAL;
108 userReadOptions_ |= OFFImporter::VERTEXTEXCOORDS;
111 userWriteOptions_ |= OFFImporter::BINARY;
113 userWriteOptions_ |= OFFImporter::VERTEXCOLOR;
115 userWriteOptions_ |= OFFImporter::FACECOLOR;
117 userWriteOptions_ |= OFFImporter::COLORALPHA;
119 userWriteOptions_ |= OFFImporter::VERTEXNORMAL;
121 userWriteOptions_ |= OFFImporter::VERTEXTEXCOORDS;
128 return QString( tr(
"Object File Format files ( *.off )") );
134 return QString( tr(
"Object File Format files ( *.off )") );
146 void FileOFFPlugin::trimString( std::string& _string) {
149 size_t start = _string.find_first_not_of(
" \t\r\n");
150 size_t end = _string.find_last_not_of(
" \t\r\n");
152 if(( std::string::npos == start ) || ( std::string::npos == end))
155 _string = _string.substr( start, end-start+1 );
166 std::getline(ifs,_string);
172 if ( _string.size() != 0 ) {
175 if ( _string[0] !=
'#') {
180 if ( !_skipEmptyLines )
185 std::cerr <<
"End of file reached while searching for input!" << std::endl;
202 if( OpenFlipper::Options::nogui() )
206 if(loadVertexColor_) {
207 if(loadVertexColor_->isChecked()) userReadOptions_ |= OFFImporter::VERTEXCOLOR;
208 else {
if(userReadOptions_ & OFFImporter::VERTEXCOLOR) userReadOptions_ -= OFFImporter::VERTEXCOLOR; }
211 if(loadFaceColor_->isChecked()) userReadOptions_ |= OFFImporter::FACECOLOR;
212 else {
if(userReadOptions_ & OFFImporter::FACECOLOR) userReadOptions_ -= OFFImporter::FACECOLOR; }
215 if(loadAlpha_->isChecked()) userReadOptions_ |= OFFImporter::COLORALPHA;
216 else {
if(userReadOptions_ & OFFImporter::COLORALPHA) userReadOptions_ -= OFFImporter::COLORALPHA; }
219 if(loadNormals_->isChecked()) userReadOptions_ |= OFFImporter::VERTEXNORMAL;
220 else {
if(userReadOptions_ & OFFImporter::VERTEXNORMAL) userReadOptions_ -= OFFImporter::VERTEXNORMAL; }
223 if(loadTexCoords_->isChecked()) userReadOptions_ |= OFFImporter::VERTEXTEXCOORDS;
224 else {
if(userReadOptions_ & OFFImporter::VERTEXTEXCOORDS) userReadOptions_ -= OFFImporter::VERTEXTEXCOORDS; }
229 if(saveBinary_->isChecked()) userWriteOptions_ |= OFFImporter::BINARY;
230 else {
if(userWriteOptions_ & OFFImporter::BINARY) userWriteOptions_ -= OFFImporter::BINARY; }
232 if(saveVertexColor_) {
233 if(saveVertexColor_->isChecked()) userWriteOptions_ |= OFFImporter::VERTEXCOLOR;
234 else {
if(userWriteOptions_ & OFFImporter::VERTEXCOLOR) userWriteOptions_ -= OFFImporter::VERTEXCOLOR; }
237 if(saveFaceColor_->isChecked()) userWriteOptions_ |= OFFImporter::FACECOLOR;
238 else {
if(userWriteOptions_ & OFFImporter::FACECOLOR) userWriteOptions_ -= OFFImporter::FACECOLOR; }
241 if(saveAlpha_->isChecked()) userWriteOptions_ |= OFFImporter::COLORALPHA;
242 else {
if(userWriteOptions_ & OFFImporter::COLORALPHA) userWriteOptions_ -= OFFImporter::COLORALPHA; }
245 if(saveNormals_->isChecked()) userWriteOptions_ |= OFFImporter::VERTEXNORMAL;
246 else {
if(userWriteOptions_ & OFFImporter::VERTEXNORMAL) userWriteOptions_ -= OFFImporter::VERTEXNORMAL; }
249 if(saveTexCoords_->isChecked()) userWriteOptions_ |= OFFImporter::VERTEXTEXCOORDS;
250 else {
if(userWriteOptions_ & OFFImporter::VERTEXTEXCOORDS) userWriteOptions_ -= OFFImporter::VERTEXTEXCOORDS; }
269 const unsigned int LINE_LEN = 4096;
272 std::ifstream ifs(_filename.toUtf8(), std::ios_base::binary);
274 if ( (!ifs.is_open()) || (!ifs.good())) {
276 emit log(
LOGERR, tr(
"Error: Could not read file options of specified OFF-file! Aborting."));
281 char line[LINE_LEN], *p;
282 ifs.getline(line, LINE_LEN);
285 int remainingChars = ifs.gcount();
288 while(remainingChars > 0) {
290 if ( ( remainingChars > 1 ) && ( p[0] ==
'S' && p[1] ==
'T') ) {
291 _importer.
addOption(OFFImporter::VERTEXTEXCOORDS);
294 }
else if ( ( remainingChars > 0 ) && ( p[0] ==
'C') ) {
295 _importer.
addOption(OFFImporter::VERTEXCOLOR);
298 }
else if ( ( remainingChars > 0 ) && ( p[0] ==
'N') ) {
299 _importer.
addOption(OFFImporter::VERTEXNORMAL);
302 }
else if ( ( remainingChars > 0 ) && (p[0] ==
'3' ) ) {
305 }
else if ( ( remainingChars > 0 ) && (p[0] ==
'4' ) ) {
307 std::cerr <<
"Error: Extended coordinates are currently not supported!" << std::endl;
310 }
else if ( ( remainingChars > 0 ) && (p[0] ==
'n' ) ) {
312 std::cerr <<
"Error: n-dimensional coordinates are currently not supported!" << std::endl;
315 }
else if ( ( remainingChars >= 3 ) && (p[0] ==
'O' && p[1] ==
'F' && p[2] ==
'F') ) {
319 }
else if ( ( remainingChars >= 6 ) && ( strncmp(p,
"BINARY", 6) == 0 ) ) {
320 _importer.
addOption(OFFImporter::BINARY);
323 }
else if ( ( remainingChars > 0 ) && ( p[0] ==
'#' ) ) {
336 unsigned int nV, nF, dummy_uint;
337 unsigned int vertexCount = 0;
338 unsigned int tmp_count = 0;
341 std::istringstream sstr;
343 if(_importer.isBinary()) {
350 readValue(ifs, dummy_uint);
352 for (
unsigned int i=0; i<nV && !ifs.eof(); ++i) {
354 for(
int index = 0; index < 3; ++index) readValue(ifs, dummy_f);
357 for(
int index = 0; index < 3; ++index) readValue(ifs, dummy_f);
360 if ( _importer.hasVertexColors() ) {
361 for(
int index = 0; index < 3; ++index) readValue(ifs, dummy_f);
364 if ( _importer.hasTextureCoords() ) {
365 for(
int index = 0; index < 2; ++index) readValue(ifs, dummy_f);
369 for (
unsigned int i=0; i<nF; ++i) {
371 readValue(ifs, tmp_count);
376 if(tmp_count > vertexCount) vertexCount = tmp_count;
381 for(
unsigned int count = 0; count < tmp_count; ++count) readValue(ifs, dummy_uint);
384 readValue(ifs, tmp_count);
386 if(!_importer.hasFaceColors() && tmp_count > 0) {
387 _importer.
addOption(OFFImporter::FACECOLOR);
391 for (
unsigned int count = 0; count < tmp_count; ++count) {
392 readValue(ifs, dummy_f);
405 if ( str.compare(
"OFF") == 0 ) {
416 for(
unsigned int i = 0; i < nV; ++i) {
423 for(
unsigned int i = 0; i < nF; ++i) {
430 if(tmp_count > vertexCount) vertexCount = tmp_count;
433 for(
unsigned int count = 0; count < tmp_count; ++count) {
436 emit log(
LOGERR,
"The OFF File is Malformatted! Aborting...");
444 if(!_importer.hasFaceColors()) {
446 _importer.
addOption(OFFImporter::FACECOLOR);
454 _importer.maxFaceValence(vertexCount);
456 if(vertexCount == 3) {
457 _importer.
addOption(OFFImporter::TRIMESH);
459 }
else if (vertexCount == 0 && nF != 0) {
463 _importer.
addOption(OFFImporter::POLYMESH);
473 QFile theFile(_filename);
474 if ( !theFile.exists() ){
475 emit log(
LOGERR, tr(
"Unable to load OFF file. File not found!"));
486 std::ifstream ifile(_filename.toUtf8(), (_importer.isBinary() ? std::ios::binary | std::ios::in
489 unsigned long sz = theFile.size()/1024/1024;
491 if(sz <= 2 * Utils::Memory::queryFreeRAM())
493 ifile.rdbuf()->pubsetbuf(NULL,theFile.size());
496 if (!ifile.is_open() || !ifile.good())
498 emit log(
LOGERR, tr(
"Cannot open OFF file for reading!"));
504 int triMeshControl = TYPEAUTODETECT;
506 if ( OpenFlipper::Options::gui() ){
507 if ( triMeshHandling_ != 0 ){
508 triMeshControl = triMeshHandling_->currentIndex();
510 triMeshControl = TYPEAUTODETECT;
514 if ( forceTriangleMesh_ )
515 triMeshControl = TYPETRIANGLE;
517 if ( forcePolyMesh_ )
518 triMeshControl = TYPEPOLY;
522 switch (triMeshControl) {
529 if( !OpenFlipper::Options::nogui() ) {
531 QMetaObject::invokeMethod(
this,
"handleTrimeshDialog",Qt::BlockingQueuedConnection);
533 if (trimeshOptions_ == OFFImporter::TRIMESH)
535 else if (trimeshOptions_ == OFFImporter::POLYMESH)
562 return _importer.isBinary() ?
parseBinary(ifile, _importer, type, _filename) :
parseASCII(ifile, _importer, type, _filename);
568 QPushButton *detectButton = msgBox.addButton(tr(
"Auto-Detect"), QMessageBox::ActionRole);
569 QPushButton *triButton = msgBox.addButton(tr(
"Open as triangle mesh"), QMessageBox::ActionRole);
570 QPushButton *polyButton = msgBox.addButton(tr(
"Open as poly mesh"), QMessageBox::ActionRole);
571 msgBox.setWindowTitle( tr(
"Mesh types in file") );
572 msgBox.setText( tr(
"You are about to open a file containing one or more mesh types. \n\n Which mesh type should be used?") );
573 msgBox.setDefaultButton( detectButton );
577 if (msgBox.clickedButton() == triButton)
578 trimeshOptions_ = OFFImporter::TRIMESH ;
579 else if (msgBox.clickedButton() == polyButton)
580 trimeshOptions_ = OFFImporter::POLYMESH ;
588 unsigned int nV, nF, dummy;
595 std::vector<VertexHandle> vhandles;
599 emit addEmptyObject(_type, objectId);
603 emit log(
LOGERR, tr(
"Could not create new object!"));
608 QFileInfo f(_objectName);
609 object->setName(f.fileName());
615 std::istringstream sstr;
630 _importer.reserve(nV, nF * _importer.maxFaceValence() , nF);
636 if ( (c ==
'\n') || (c ==
'#') )
637 std::getline(_in, tmp);
643 for (uint i=0; i<nV && !_in.eof(); ++i) {
646 v[0] = getFloat(_in);
647 v[1] = getFloat(_in);
648 v[2] = getFloat(_in);
650 const VertexHandle vh = _importer.
addVertex(v);
655 n[0] = getFloat(_in);
656 n[1] = getFloat(_in);
657 n[2] = getFloat(_in);
659 if(userReadOptions_ & OFFImporter::VERTEXNORMAL) {
669 int colorType =
getColorType(line, _importer.hasTextureCoords() );
672 if ( _importer.hasVertexColors() ){
678 case 1 : sstr >> trash;
break;
679 case 2 : sstr >> trash; sstr >> trash;
break;
685 if ( userReadOptions_ & OFFImporter::VERTEXCOLOR ) {
686 int cidx = _importer.
addColor( OpenMesh::color_cast<PolyMesh::Color>( c3 ) );
696 if ( userReadOptions_ & OFFImporter::VERTEXCOLOR ) {
697 int cidx = _importer.
addColor( OpenMesh::color_cast<PolyMesh::Color>( c4 ) );
699 _importer.
addOption(OFFImporter::COLORALPHA);
704 c3f[0] = getFloat(sstr);
705 c3f[1] = getFloat(sstr);
706 c3f[2] = getFloat(sstr);
707 if ( userReadOptions_ & OFFImporter::VERTEXCOLOR ) {
708 int cidx = _importer.
addColor( OpenMesh::color_cast<PolyMesh::Color>(c3f) );
714 c4f[0] = getFloat(sstr);
715 c4f[1] = getFloat(sstr);
716 c4f[2] = getFloat(sstr);
717 c4f[3] = getFloat(sstr);
718 if ( userReadOptions_ & OFFImporter::VERTEXCOLOR ) {
719 int cidx = _importer.
addColor( OpenMesh::color_cast<PolyMesh::Color>(c4f) );
721 _importer.
addOption(OFFImporter::COLORALPHA);
726 std::cerr <<
"Error in file format (colorType = " << colorType <<
")\n";
732 if ( _importer.hasTextureCoords() ){
733 t[0] = getFloat(sstr);
734 t[1] = getFloat(sstr);
735 if ( userReadOptions_ & OFFImporter::VERTEXTEXCOORDS ) {
745 if ( (c ==
'\n') || (c ==
'#') )
746 std::getline(_in, tmp);
753 for (uint i=0; i<nF; ++i)
768 for (
unsigned int count=0; count<nV; ++count) {
770 vhandles.push_back(VertexHandle(idx));
773 bool checkManifold =
true;
774 if(!OpenFlipper::Options::nogui() && loadCheckManifold_ != 0) {
775 checkManifold = loadCheckManifold_->isChecked();
781 fh = _importer.
addFace(vhandles);
786 fh = _importer.
addFace(vhandles);
790 if ( _importer.hasFaceColors() ){
803 case 1 : sstr >> trash;
break;
804 case 2 : sstr >> trash; sstr >> trash;
break;
810 if ( userReadOptions_ & OFFImporter::FACECOLOR ) {
811 int cidx = _importer.
addColor( OpenMesh::color_cast<PolyMesh::Color>( c3 ) );
821 if ( userReadOptions_ & OFFImporter::FACECOLOR ) {
822 int cidx = _importer.
addColor( OpenMesh::color_cast<PolyMesh::Color>( c4 ) );
824 _importer.
addOption(OFFImporter::COLORALPHA);
829 c3f[0] = getFloat(sstr);
830 c3f[1] = getFloat(sstr);
831 c3f[2] = getFloat(sstr);
832 if ( userReadOptions_ & OFFImporter::FACECOLOR ) {
833 int cidx = _importer.
addColor( OpenMesh::color_cast<PolyMesh::Color>(c3f) );
839 c4f[0] = getFloat(sstr);
840 c4f[1] = getFloat(sstr);
841 c4f[2] = getFloat(sstr);
842 c4f[3] = getFloat(sstr);
843 if ( userReadOptions_ & OFFImporter::FACECOLOR ) {
844 int cidx = _importer.
addColor( OpenMesh::color_cast<PolyMesh::Color>(c4f) );
846 _importer.
addOption(OFFImporter::COLORALPHA);
851 std::cerr <<
"Error in file format (colorType = " << colorType <<
")\n";
866 int size = _v.size();
868 for(
int i = 0; i < size; ++i) {
869 for(
int j = i+1; j < size; ++j) {
870 if(_v[i] == _v[j]) check =
false;
890 if ( _line.size() < 1 )
900 found=_line.find_first_of(
" ");
901 while (found!=std::string::npos){
903 found=_line.find_first_of(
" ",found+1);
906 if (!_line.empty()) count++;
908 if (_texCoordsAvailable) count -= 2;
910 if (count == 3 || count == 4){
912 found = _line.find(
" ");
913 std::string c1 = _line.substr (0,found);
915 if (c1.find(
".") != std::string::npos){
930 unsigned int nV, nF, dummy;
936 std::vector<VertexHandle> vhandles;
940 emit addEmptyObject(_type, objectId);
944 emit log(
LOGERR, tr(
"Could not create new object!"));
949 QFileInfo f(_objectName);
950 object->setName(f.fileName());
962 readValue(_in, dummy);
965 _importer.reserve(nV, nF * _importer.maxFaceValence() , nF);
968 for (uint i=0; i<nV && !_in.eof(); ++i)
971 readValue(_in, v[0]);
972 readValue(_in, v[1]);
973 readValue(_in, v[2]);
975 const VertexHandle vh = _importer.
addVertex(v);
978 readValue(_in, n[0]);
979 readValue(_in, n[1]);
980 readValue(_in, n[2]);
982 if ( userReadOptions_ & OFFImporter::VERTEXNORMAL ) {
988 if ( _importer.hasVertexColors() ) {
990 readValue(_in, c[0]);
991 readValue(_in, c[1]);
992 readValue(_in, c[2]);
995 if ( userReadOptions_ & OFFImporter::VERTEXCOLOR ) {
1001 if ( _importer.hasTextureCoords() ) {
1002 readValue(_in, t[0]);
1003 readValue(_in, t[1]);
1005 if ( userReadOptions_ & OFFImporter::VERTEXTEXCOORDS ) {
1017 for (uint i = 0; i<nF && !_in.eof(); ++i)
1022 _in.seekg(0, std::ios::end);
1055 readColorComp_ =
false;
1070 for (uint j = 0; j < nV; ++j) {
1071 readValue(_in, dummy);
1075 if (readColorComp_) {
1078 for (uint j = 0; j < nV; ++j) {
1079 readValue(_in, dummy_f);
1088 for (uint j = 0; j < nV; ++j) {
1089 readValue(_in, idx);
1090 vhandles.push_back(VertexHandle(idx));
1093 fh = _importer.
addFace(vhandles);
1095 if ( !readColorComp_ ) {
1107 if ( nV == 3 || nV == 4 ) {
1110 for(uint k = 0; k < 3; ++k) {
1111 readValue(_in, c[k]);
1117 readValue(_in, alpha);
1120 if(userReadOptions_ & OFFImporter::FACECOLOR) {
1121 if(userReadOptions_ & OFFImporter::COLORALPHA) {
1124 _importer.
addOption(OFFImporter::COLORALPHA);
1126 int cidx = _importer.
addColor(OpenMesh::color_cast<OpenMesh::Vec4f>(c));
1132 for(
unsigned int count = 0; count < nV; ++count) {
1133 readValue(_in, dummy_f);
1165 int pos = _in.tellg();
1167 for(uint k = 0; k < _nF; ++k) {
1173 for(uint z = 0; z < nV; ++z) {
1174 readValue(_in, dummy);
1179 int currPos = _in.tellg();
1184 if(_nB - currPos == 0) {
1208 forceTriangleMesh_ =
false;
1209 forcePolyMesh_ =
false;
1214 object->setFromFileName(_filename);
1221 if ( !importer.
hasVertexNormals() || (userReadOptions_ & OFFImporter::FORCE_NONORMALS) ) {
1222 emit log(
LOGINFO, tr(
"loadObject: Computing vertex and face normals.") );
1225 emit log(
LOGINFO, tr(
"loadObject: Computing face normals.") );
1237 if ( !importer.
hasVertexNormals() || (userReadOptions_ & OFFImporter::FORCE_NONORMALS) ) {
1238 emit log(
LOGINFO, tr(
"loadObject: Computing vertex and face normals.") );
1241 emit log(
LOGINFO, tr(
"loadObject: Computing face normals.") );
1250 emit openedFile( object->
id() );
1252 forceTriangleMesh_ =
false;
1253 forcePolyMesh_ =
false;
1254 return object->id();
1261 forceTriangleMesh_ =
false;
1262 forcePolyMesh_ =
false;
1265 forceTriangleMesh_ =
true;
1267 forcePolyMesh_ =
true;
1275 bool FileOFFPlugin::saveObject(
int _id, QString _filename)
1279 emit log(
LOGERR, tr(
"saveObject : cannot get object id %1 for save name %2").arg(_id).arg(_filename) );
1283 std::string filename = std::string( _filename.toUtf8() );
1285 bool binary = userWriteOptions_ & OFFImporter::BINARY;
1286 std::fstream ofs( filename.c_str(), (binary ? std::ios_base::out | std::ios_base::binary : std::ios_base::out));
1290 emit log(
LOGERR, tr(
"saveObject : Cannot not open file %1 for writing!").arg(_filename) );
1299 object->setFromFileName(_filename);
1300 object->setName(object->
filename());
1305 emit log(
LOGINFO, tr(
"Saved object to ") + _filename );
1309 emit log(
LOGERR, tr(
"Unable to save ") + _filename);
1315 object->setFromFileName(_filename);
1316 object->setName(object->
filename());
1321 emit log(
LOGINFO, tr(
"Saved object to ") + _filename );
1325 emit log(
LOGERR, tr(
"Unable to save ") + _filename );
1330 emit log(
LOGERR, tr(
"Unable to save (object is not a compatible mesh type)"));
1338 template <
class MeshT>
1342 if (_mesh.has_vertex_texcoords2D()) {
1345 if (!_mesh.get_property_handle(oldVertexCoords,
"Original Per Vertex Texture Coords"))
1346 _mesh.add_property(oldVertexCoords,
"Original Per Vertex Texture Coords");
1348 for (
typename MeshT::VertexIter v_it = _mesh.vertices_begin(); v_it != _mesh.vertices_end(); ++v_it)
1349 _mesh.property(oldVertexCoords, *v_it) = _mesh.texcoord2D(*v_it);
1354 if (_mesh.has_halfedge_texcoords2D()) {
1357 if (!_mesh.get_property_handle(oldHalfedgeCoords,
"Original Per Face Texture Coords"))
1358 _mesh.add_property(oldHalfedgeCoords,
"Original Per Face Texture Coords");
1360 for (
typename MeshT::HalfedgeIter he_it = _mesh.halfedges_begin(); he_it != _mesh.halfedges_end(); ++he_it)
1361 _mesh.property(oldHalfedgeCoords, *he_it) = _mesh.texcoord2D(*he_it);
1370 if (saveOptions_ == 0){
1372 saveOptions_ =
new QWidget();
1373 QVBoxLayout* layout =
new QVBoxLayout();
1374 layout->setAlignment(Qt::AlignTop);
1376 saveBinary_ =
new QCheckBox(
"Save Binary");
1377 layout->addWidget(saveBinary_);
1379 saveVertexColor_ =
new QCheckBox(
"Save Vertex Colors");
1380 layout->addWidget(saveVertexColor_);
1382 saveFaceColor_ =
new QCheckBox(
"Save Face Colors");
1383 layout->addWidget(saveFaceColor_);
1385 saveAlpha_ =
new QCheckBox(
"Save Color Alpha");
1386 layout->addWidget(saveAlpha_);
1388 saveNormals_ =
new QCheckBox(
"Save Normals");
1389 layout->addWidget(saveNormals_);
1391 saveTexCoords_ =
new QCheckBox(
"Save TexCoords");
1392 layout->addWidget(saveTexCoords_);
1394 savePrecisionLabel_ =
new QLabel(
"Writer Precision");
1395 layout->addWidget(savePrecisionLabel_);
1397 savePrecision_ =
new QSpinBox();
1398 savePrecision_->setMinimum(1);
1399 savePrecision_->setMaximum(12);
1400 savePrecision_->setValue(6);
1401 layout->addWidget(savePrecision_);
1403 saveDefaultButton_ =
new QPushButton(
"Make Default");
1404 layout->addWidget(saveDefaultButton_);
1406 saveOptions_->setLayout(layout);
1408 connect(saveBinary_, SIGNAL(clicked(
bool)), savePrecision_, SLOT(setDisabled(
bool)));
1409 connect(saveDefaultButton_, SIGNAL(clicked()),
this, SLOT(
slotSaveDefault()));
1411 saveBinary_->setChecked(
OpenFlipperSettings().value(
"FileOff/Save/Binary",
false).toBool() );
1412 saveVertexColor_->setChecked(
OpenFlipperSettings().value(
"FileOff/Save/VertexColor",
true).toBool() );
1413 saveFaceColor_->setChecked(
OpenFlipperSettings().value(
"FileOff/Save/FaceColor",
true).toBool() );
1414 saveAlpha_->setChecked(
OpenFlipperSettings().value(
"FileOff/Save/Alpha",
true).toBool() );
1415 saveNormals_->setChecked(
OpenFlipperSettings().value(
"FileOff/Save/Normals",
true).toBool() );
1416 saveTexCoords_->setChecked(
OpenFlipperSettings().value(
"FileOff/Save/TexCoords",
true).toBool() );
1420 return saveOptions_;
1427 if (loadOptions_ == 0){
1429 loadOptions_ =
new QWidget();
1430 QVBoxLayout* layout =
new QVBoxLayout();
1431 layout->setAlignment(Qt::AlignTop);
1433 QLabel* label =
new QLabel(tr(
"If PolyMesh is a Triangle Mesh:"));
1435 layout->addWidget(label);
1437 triMeshHandling_ =
new QComboBox();
1438 triMeshHandling_->addItem( tr(
"Auto-Detect") );
1439 triMeshHandling_->addItem( tr(
"Ask") );
1440 triMeshHandling_->addItem( tr(
"Always open as PolyMesh") );
1441 triMeshHandling_->addItem( tr(
"Always open as TriangleMesh") );
1443 layout->addWidget(triMeshHandling_);
1445 loadVertexColor_ =
new QCheckBox(
"Load Vertex Colors");
1446 layout->addWidget(loadVertexColor_);
1448 loadFaceColor_ =
new QCheckBox(
"Load Face Colors");
1449 layout->addWidget(loadFaceColor_);
1451 loadAlpha_ =
new QCheckBox(
"Load Color Alpha");
1452 layout->addWidget(loadAlpha_);
1454 loadNormals_ =
new QCheckBox(
"Load Normals");
1455 layout->addWidget(loadNormals_);
1457 loadTexCoords_ =
new QCheckBox(
"Load TexCoords");
1458 layout->addWidget(loadTexCoords_);
1460 loadCheckManifold_ =
new QCheckBox(
"Check for manifold configurations");
1461 layout->addWidget(loadCheckManifold_);
1463 loadDefaultButton_ =
new QPushButton(
"Make Default");
1464 layout->addWidget(loadDefaultButton_);
1466 loadOptions_->setLayout(layout);
1468 connect(loadDefaultButton_, SIGNAL(clicked()),
this, SLOT(
slotLoadDefault()));
1470 triMeshHandling_->setCurrentIndex(
OpenFlipperSettings().value(
"FileOff/Load/TriMeshHandling",TYPEAUTODETECT ).toInt() );
1472 loadVertexColor_->setChecked(
OpenFlipperSettings().value(
"FileOff/Load/VertexColor",
true).toBool() );
1473 loadFaceColor_->setChecked(
OpenFlipperSettings().value(
"FileOff/Load/FaceColor",
true).toBool() );
1474 loadAlpha_->setChecked(
OpenFlipperSettings().value(
"FileOff/Load/Alpha",
true).toBool() );
1475 loadNormals_->setChecked(
OpenFlipperSettings().value(
"FileOff/Load/Normals",
true).toBool() );
1476 loadTexCoords_->setChecked(
OpenFlipperSettings().value(
"FileOff/Load/TexCoords",
true).toBool() );
1479 return loadOptions_;
void removeOption(ObjectOptionsE _option)
remove an option
#define DATA_TRIANGLE_MESH
DataType supportedType()
Return your supported object type( e.g. DATA_TRIANGLE_MESH )
const UpdateType UPDATE_ALL(UpdateTypeSet(1))
Identifier for all updates.
Type for a Meshobject containing a poly mesh.
int getColorType(std::string &_line, bool _texCoordsAvailable)
Get color type.
bool parseBinary(std::istream &_in, OFFImporter &_importer, DataType _type, QString &_objectName)
Parse binary OFF file.
bool getObject(const int _identifier, BaseObject *&_object)
Get the object which has the given identifier.
bool extendedFaceColorTest(std::istream &_in, uint _nV, uint _nF, int _nB) const
Test if there are face color components (_nV is the initial face valence)
BaseObject * getObject()
get BaseObject data of object
void initializePlugin()
Initialize Plugin.
void backupTextureCoordinates(MeshT &_mesh)
backup per vertex/face texture coordinates
void slotLoadDefault()
Slot called when user wants to save the given Load options as default.
QString filename() const
return the filename of the object
void setNormal(VertexHandle _vh, int _normalID)
set vertex normal
void setVertexColor(VertexHandle _vh, int _colorIndex)
set vertex color
MeshT * mesh()
return a pointer to the mesh
bool hasVertexNormals()
Query Object Options.
bool dataType(DataType _type) const
bool parseASCII(std::istream &_in, OFFImporter &_importer, DataType _type, QString &_objectName)
Parse ascii OFF file.
void slotSaveDefault()
Slot called when user wants to save the given Save options as default.
bool writeMesh(std::ostream &_out, MeshT &_mesh, BaseObject &_baseObj)
Writer function.
int loadObject(QString _filename)
Loads Object and converts it to a triangle mesh if possible.
void setVertexTexCoord(VertexHandle _vh, int _texCoordID)
set vertex texture coordinate
int addFace(const VHandles &_indices)
add a face with indices _indices refering to vertices
void addObject(BaseObject *_object)
add initial object
FileOFFPlugin()
Constructor.
void addOption(ObjectOptionsE _option)
add an option
int addNormal(const Vec3f &_normal)
add a normal
Type for a MeshObject containing a triangle mesh.
void handleTrimeshDialog()
Displays a dialog to ask how to load the mesh (triangle, polymesh , autodetect)
void update_normals()
Compute normals for all primitives.
QWidget * loadOptionsWidget(QString)
VertexHandle addVertex(const Vec3f &_point)
add a vertex with coordinate _point
QWidget * saveOptionsWidget(QString)
void update_face_normals()
Update normal vectors for all faces.
bool getCleanLine(std::istream &ifs, std::string &_string, bool _skipEmptyLines=true)
Function to retrieve next line.
int addColor(const Vec4f &_color)
add a color
int addTexCoord(const Vec2f &_coord)
add texture coordinates
void setValue(const QString &key, const QVariant &value)
Wrapper function which makes it possible to enable Debugging output with -DOPENFLIPPER_SETTINGS_DEBUG...
bool readOFFFile(QString _filename, OFFImporter &_importer)
Read OFF file and parse it.
DLLEXPORT OpenFlipperQSettings & OpenFlipperSettings()
QSettings object containing all program settings of OpenFlipper.
bool readFileOptions(QString _filename, OFFImporter &_importer)
Before Parsing the actual file, read all features supported.
void setFaceColor(FaceHandle _fh, int _colorIndex)
set face color
bool checkDegenerateFace(const std::vector< VertexHandle > &_v)
Check for degenerate faces before adding them.