File: io_expe.cpp

package info (click to toggle)
meshlab 2020.09%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 45,132 kB
  • sloc: cpp: 400,238; ansic: 31,952; javascript: 1,578; sh: 387; yacc: 238; lex: 139; python: 86; makefile: 30
file content (186 lines) | stat: -rw-r--r-- 7,042 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
/****************************************************************************
* MeshLab                                                           o o     *
* An extendible mesh processor                                    o     o   *
*                                                                _   O  _   *
* Copyright(C) 2005, 2006                                          \/)\/    *
* Visual Computing Lab                                            /\/|      *
* ISTI - Italian National Research Council                           |      *
*                                                                    \      *
* All rights reserved.                                                      *
*                                                                           *
* This program is free software; you can redistribute it and/or modify      *
* it under the terms of the GNU General Public License as published by      *
* the Free Software Foundation; either version 2 of the License, or         *
* (at your option) any later version.                                       *
*                                                                           *
* This program is distributed in the hope that it will be useful,           *
* but WITHOUT ANY WARRANTY; without even the implied warranty of            *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             *
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt)          *
* for more details.                                                         *
*                                                                           *
****************************************************************************/

#include <Qt>

#include "io_expe.h"

#include <wrap/io_trimesh/export.h>
#include <wrap/io_trimesh/io_mask.h>

#include "import_expe.h"
#include "import_xyz.h"
#include "export_xyz.h"
// #include "export_expe.h"

#include <QMessageBox>

using namespace std;
using namespace vcg;



bool ExpeIOPlugin::open(const QString &formatName, const QString &fileName, MeshModel &m, int& mask, const RichParameterList & /*parlst*/, CallBackPos *cb, QWidget *parent)
{
	// initializing mask
	mask = 0;

	// initializing progress bar status
	if (cb != NULL)		(*cb)(0, "Loading...");

	QString errorMsgFormat = "Error encountered while loading file:\n\"%1\"\n\nError details: %2";
	QString error_2MsgFormat = "Error encountered while loading file:\n\"%1\"\n\n File with more than a mesh.\n Load only the first!";

	string filename = QFile::encodeName(fileName).constData ();
    bool useXYZ=false;
	if ( (formatName.toLower() == tr("pts")) || (formatName.toLower() == tr("apts")) )
    {
      int loadMask;
      if (!vcg::tri::io::ImporterExpePTS<CMeshO>::LoadMask(filename.c_str(),loadMask))
      {
        useXYZ=true;
        if (!vcg::tri::io::ImporterXYZ<CMeshO>::LoadMask(filename.c_str(),loadMask)) 
          return false;
      }        
      m.Enable(loadMask);
      int result;
      if(useXYZ) {
        result = vcg::tri::io::ImporterXYZ<CMeshO>::Open(m.cm, filename.c_str(), mask, cb);     
        if (result != 0)
        {
          QMessageBox::warning(parent, tr("PTX Point Set Opening Error"),
                               errorMsgFormat.arg(fileName, vcg::tri::io::ImporterXYZ<CMeshO>::ErrorMsg(result)));
          return false;
        }
      }
      else 
      {
        result = vcg::tri::io::ImporterExpePTS<CMeshO>::Open(m.cm, filename.c_str(), mask, cb);     
        if (result != 0)
        {
          QMessageBox::warning(parent, tr("Expe Point Set Opening Error"),
                               errorMsgFormat.arg(fileName, vcg::tri::io::ImporterExpePTS<CMeshO>::ErrorMsg(result)));
          return false;
        }
      }
      
    }
  else if (formatName.toLower() == tr("xyz"))
  {
    int loadMask;
    if (!vcg::tri::io::ImporterXYZ<CMeshO>::LoadMask(filename.c_str(),loadMask))
      return false;
    m.Enable(loadMask);


    int result = vcg::tri::io::ImporterXYZ<CMeshO>::Open(m.cm, filename.c_str(), mask, cb);
    if (result != 0)
    {
      QMessageBox::warning(parent, tr("XYZ Opening Error"),
                           errorMsgFormat.arg(fileName, vcg::tri::io::ImporterXYZ<CMeshO>::ErrorMsg(result)));
      return false;
    }
  }

	vcg::tri::UpdateBounding<CMeshO>::Box(m.cm);					// updates bounding box

	if (cb != NULL)
		(*cb)(99, "Done");

	return true;
}

bool ExpeIOPlugin::save(const QString &formatName, const QString &fileName, MeshModel &m, const int mask, const RichParameterList &, vcg::CallBackPos * /*cb*/, QWidget *parent)
{
	QString errorMsgFormat = "Error encountered while exporting file %1:\n%2";
	string filename = QFile::encodeName(fileName).constData ();
	string ex = formatName.toUtf8().data();

// 	if( formatName.toUpper() == tr("GTS") )
// 	{
// 		int result = vcg::tri::io::ExporterGTS<CMeshO>::Save(m.cm,filename.c_str(),mask);
// 		if(result!=0)
// 		{
// 			QMessageBox::warning(parent, tr("Saving Error"), errorMsgFormat.arg(fileName, vcg::tri::io::ExporterGTS<CMeshO>::ErrorMsg(result)));
// 			return false;
// 		}
// 		return true;
// 	}

  if(formatName.toLower() == tr("xyz"))
  {
    int result = vcg::tri::io::ExporterXYZ<CMeshO>::Save(m.cm,filename.c_str(),mask);
    if(result!=0)
    {
      QMessageBox::warning(parent, tr("Saving Error"), errorMsgFormat.arg(fileName, vcg::tri::io::ExporterXYZ<CMeshO>::ErrorMsg(result)));
      return false;
    }
    return true;
  }

	assert(0); // unknown format
	return false;
}

/*
	returns the list of the file's type which can be imported
*/
QString ExpeIOPlugin::pluginName() const
{
	return "IOExpe";
}

QList<MeshIOInterface::Format> ExpeIOPlugin::importFormats() const
{
	QList<Format> formatList;
	formatList << Format("Expe's point set (binary)"		,tr("pts"));
	formatList << Format("Expe's point set (ascii)"			,tr("apts"));
	formatList << Format("XYZ Point Cloud (with or without normal)"				,tr("xyz"));
	return formatList;
}

/*
	returns the list of the file's type which can be exported
*/
QList<MeshIOInterface::Format> ExpeIOPlugin::exportFormats() const
{
	QList<Format> formatList;
// 	formatList << Format("Expe's point set (binary)"		,tr("pts"));
// 	formatList << Format("Expe's point set (ascii)"			,tr("apts"));
	formatList << Format("XYZ Point Cloud (with or without normal)"				,tr("xyz"));
	return formatList;
}

/*
	returns the mask on the basis of the file's type.
	otherwise it returns 0 if the file format is unknown
*/
void ExpeIOPlugin::GetExportMaskCapability(QString &format, int &capability, int &defaultBits) const
{
// 	if(format.toLower() == tr("apts")){capability=defaultBits= vcg::tri::io::ExporterExpeAPTS<CMeshO>::GetExportMaskCapability();}
// 	if(format.toLower() == tr("pts")){capability=defaultBits= vcg::tri::io::ExporterExpePTS<CMeshO>::GetExportMaskCapability();}
 	if(format.toLower() == tr("xyz")){capability=defaultBits= vcg::tri::io::ExporterXYZ<CMeshO>::GetExportMaskCapability();}
	return;
}

MESHLAB_PLUGIN_NAME_EXPORTER(ExpeIOPlugin)