File: filter_bnpts.cpp

package info (click to toggle)
meshlab 1.3.2+dfsg1-4
  • links: PTS, VCS
  • area: main
  • in suites: buster, sid
  • size: 21,096 kB
  • ctags: 33,630
  • sloc: cpp: 224,813; ansic: 8,170; xml: 119; makefile: 80
file content (159 lines) | stat: -rw-r--r-- 5,322 bytes parent folder | download | duplicates (3)
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
/****************************************************************************
* MeshLab                                                           o o     *
* A versatile mesh processing toolbox                             o     o   *
*                                                                _   O  _   *
* Copyright(C) 2005                                                \/)\/    *
* 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 <QFileDialog>
#include "filter_bnpts.h"

using namespace std;
using namespace vcg;

// Constructor
FilterBnptsPlugin::FilterBnptsPlugin()
{
	typeList <<
	FP_BNPTSGEN;

	foreach(FilterIDType tt , types())
		actionList << new QAction(filterName(tt), this);
}

// ST() return the very short string describing each filtering action
QString FilterBnptsPlugin::filterName(FilterIDType filterId) const
{
	switch(filterId) {
		case FP_BNPTSGEN	:	return QString("generate a BNPTS file for out-of-core poisson");
		default : assert(0);
	}
}

// Info() return the longer string describing each filtering action
 QString FilterBnptsPlugin::filterInfo(FilterIDType filterId) const
{
	switch(filterId) {
		case FP_BNPTSGEN	:	return QString("generate a BNPTS file using data from all layers. This file contains points+normals and it is used with the external tool for out-of-core poisson merging");
    default : assert(0);
	}
}

// This function define the needed parameters for each filter.
void FilterBnptsPlugin::initParameterSet(QAction *action, MeshDocument &md, RichParameterSet & parlst)
{
	MeshModel *mm=md.mm();
	
	switch(ID(action))
	{
		case FP_BNPTSGEN :
		{
			parlst.addParam(new RichBool ("onlyvisible",
				true,
				"Use only visible layers",
				"If true, only visible layers are used for generating the BNPTS"));
			parlst.addParam(new RichBool ("append",
				false,
				"append to existing file",
				"If true and the output files already exist, appends data to \n\n"
				"the existing BNPTS"));				
		}
		break;
   
   
		default: break; // do not add any parameter for the other filters
	}
}

// Core Function doing the actual mesh processing.
bool FilterBnptsPlugin::applyFilter(QAction *filter, MeshDocument &md, RichParameterSet & par, vcg::CallBackPos *cb)
{
	CMeshO::FaceIterator fi;

	switch(ID(filter))
	{

		case FP_BNPTSGEN :
		{
      bool onlyvisiblelayers = par.getBool("onlyvisible");
      bool appendexisting = par.getBool("append");
      CMeshO::VertexIterator vi;

      // destination file
      QString filename = QFileDialog::getSaveFileName((QWidget*)NULL,tr("Export BNPTS File"), QDir::currentPath(), tr("BNPTS file (*.Bnpts )"));
      FILE* outfile=NULL;

      if(appendexisting)
        outfile  = fopen(qPrintable(filename), "wba");
      else
        outfile  = fopen(qPrintable(filename), "wb");

      if(outfile==NULL)
        return false;

      int cnt=0;
      foreach(MeshModel *mmp, md.meshList)
      { 
        ++cnt;

        // visible ?
        if(mmp->visible || !onlyvisiblelayers)
        {
          float buff[6];
          
          // the mesh has to be correctly transformed before exporting
          tri::UpdatePosition<CMeshO>::Matrix(mmp->cm,mmp->cm.Tr,true);

          for(vi=mmp->cm.vert.begin();vi!=mmp->cm.vert.end();++vi)
					  if(!(*vi).IsD())
            {
              buff[0]=vi->P().X();
              buff[1]=vi->P().Y();
              buff[2]=vi->P().Z();
              buff[3]=vi->N().X();
              buff[4]=vi->N().Y();
              buff[5]=vi->N().Z();

              fwrite(buff,sizeof(float),6,outfile);
            }

          // the mesh has to return to its original position
          tri::UpdatePosition<CMeshO>::Matrix(mmp->cm,Inverse(mmp->cm.Tr),true);
        }     
      }

      fclose(outfile);

		} break;
	}
	
	return true;
}

FilterBnptsPlugin::FilterClass FilterBnptsPlugin::getClass(QAction *a)
{
  switch(ID(a))
  {
    case FP_BNPTSGEN :
      return MeshFilterInterface::Layer;
    default :  assert(0);
      return MeshFilterInterface::Generic;
}
}

Q_EXPORT_PLUGIN(FilterBnptsPlugin)