File: filter_camera.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 (544 lines) | stat: -rw-r--r-- 21,423 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
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
/****************************************************************************
* 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 "filter_camera.h"

#include <vcg/complex/algorithms/clean.h>


using namespace std;
using namespace vcg;

// Constructor
FilterCameraPlugin::FilterCameraPlugin()
{
	typeList <<
  FP_SET_MESH_CAMERA <<
  FP_SET_RASTER_CAMERA <<
  FP_QUALITY_FROM_CAMERA <<
  FP_CAMERA_ROTATE<<
  FP_CAMERA_SCALE<<
  FP_CAMERA_TRANSLATE<<
  FP_CAMERA_TRANSFORM <<
  FP_CAMERA_EDIT;

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

// ST() return the very short string describing each filtering action
QString FilterCameraPlugin::filterName(FilterIDType filterId) const
{
  switch(filterId) {
    case FP_SET_MESH_CAMERA :      return QString("Set Mesh Camera");
    case FP_SET_RASTER_CAMERA :    return QString("Set Raster Camera");
    case FP_QUALITY_FROM_CAMERA :  return QString("Vertex Quality from Camera");
	case FP_CAMERA_ROTATE :         return QString("Transform: Rotate Camera or set of cameras");
	case FP_CAMERA_SCALE :         return QString("Transform: Scale Camera or set of cameras");
	case FP_CAMERA_TRANSLATE :         return QString("Transform: Translate Camera or set of cameras");
 	case FP_CAMERA_TRANSFORM :        return QString("Transform the camera extrinsics, or all the cameras of the project.");
    case FP_CAMERA_EDIT :         return QString("Edit Raster Camera");
    default : assert(0);
  }
}

// Info() return the longer string describing each filtering action
QString FilterCameraPlugin::filterInfo(FilterIDType filterId) const
{
  switch(filterId) {
    case FP_SET_MESH_CAMERA :     return QString("This filter allow to set a shot for the current mesh");
    case FP_SET_RASTER_CAMERA :   return QString("This filter allow to set a shot for the current mesh");
    case FP_QUALITY_FROM_CAMERA : return QString("Compute vertex quality using the camera definition, according to viewing angle or distance");
    case FP_CAMERA_ROTATE :       return QString("Rotate the camera, or all the cameras of the project. The selected raster is the reference if viewpoint rotation is selected.");
	case FP_CAMERA_SCALE :        return QString("Scale the camera, or all the cameras of the project. The selected raster is the reference if viewpoint scaling is selected.");
	case FP_CAMERA_TRANSLATE :        return QString("Translate the camera, or all the cameras of the project.");
	case FP_CAMERA_TRANSFORM :        return QString("Transform the camera extrinsics, or all the cameras of the project.");
    case FP_CAMERA_EDIT :        return QString("Allow to edit the current raster camera allowing to tweak intrinsics.");
    default : assert(0);
  }
}

// This function define the needed parameters for each filter.
void FilterCameraPlugin::initParameterSet(QAction *action, MeshDocument &/*m*/, RichParameterSet & parlst)
{
  Shotf defShot;
	 switch(ID(action))
	 {
   case FP_CAMERA_EDIT :
     parlst.addParam(new RichDynamicFloat("fov_scale", 0, -3,3,"Scaling exp", "Exponent of the scaling factor. 0 means no scaling, 1 means 10 times larger, -1 means 1/10."));
     break;
   case FP_CAMERA_ROTATE :
	  {
	 QStringList shotType;
      shotType.push_back("Raster Camera");
      shotType.push_back("Mesh Camera");
	  parlst.addParam(new RichEnum("camera", 0, shotType, tr("Camera type"), tr("Choose the camera to scale")));
	  QStringList rotMethod;
      rotMethod.push_back("X axis");
      rotMethod.push_back("Y axis");
      rotMethod.push_back("Z axis");
      rotMethod.push_back("custom axis");
      parlst.addParam(new RichEnum("rotAxis", 0, rotMethod, tr("Rotation on:"), tr("Choose a method")));
      QStringList rotCenter;
      rotCenter.push_back("origin");
      rotCenter.push_back("camera viewpoint");
      rotCenter.push_back("custom point");
      parlst.addParam(new RichEnum("rotCenter", 0, rotCenter, tr("Center of rotation:"), tr("Choose a method")));
      parlst.addParam(new RichDynamicFloat("angle",0,-360,360,"Rotation Angle","Angle of rotation (in <b>degree</b>). If snapping is enable this vaule is rounded according to the snap value"));
      parlst.addParam(new RichPoint3f("customAxis",Point3f(0,0,0),"Custom axis","This rotation axis is used only if the 'custom axis' option is chosen."));
      parlst.addParam(new RichPoint3f("customCenter",Point3f(0,0,0),"Custom center","This rotation center is used only if the 'custom point' option is chosen."));
	 parlst.addParam(new RichBool ("toallRaster", false, "Apply to all Raster layers", "Apply the same scaling to all the Raster layers: it is taken into account only if 'Raster Camera' is selected"));
	 parlst.addParam(new RichBool ("toall", false, "Apply to all Raster and Mesh layers", "Apply the same scaling to all the layers, including any 3D layer"));
	   }
     break;
  case FP_CAMERA_SCALE :
	  {
	 QStringList shotType;
      shotType.push_back("Raster Camera");
      shotType.push_back("Mesh Camera");
	  parlst.addParam(new RichEnum("camera", 0, shotType, tr("Camera type"), tr("Choose the camera to scale")));
		QStringList scaleCenter;
		scaleCenter.push_back("origin");
		scaleCenter.push_back("camera viewpoint");
		scaleCenter.push_back("custom point");
		parlst.addParam(new RichEnum("scaleCenter", 0, scaleCenter, tr("Center of scaling:"), tr("Choose a method")));
		parlst.addParam(new RichPoint3f("customCenter",Point3f(0,0,0),"Custom center","This scaling center is used only if the 'custom point' option is chosen."));
     parlst.addParam(new RichFloat("scale", 1.0, "Scale factor", "The scale factor that has to be applied to the camera"));
	 parlst.addParam(new RichBool ("toallRaster", false, "Apply to all Raster layers", "Apply the same scaling to all the Raster layers: it is taken into account only if 'Raster Camera' is selected"));
	 parlst.addParam(new RichBool ("toall", false, "Apply to all Raster and Mesh layers", "Apply the same scaling to all the layers, including any 3D layer"));
	   }
     break;
   case FP_CAMERA_TRANSLATE :
	  {
		QStringList shotType;
        shotType.push_back("Raster Camera");
        shotType.push_back("Mesh Camera");
	    parlst.addParam(new RichEnum("camera", 0, shotType, tr("Camera type"), tr("Choose the camera to scale")));
	    parlst.addParam(new RichDynamicFloat("axisX",0,-1000,1000,"X Axis","Absolute translation amount along the X axis"));
        parlst.addParam(new RichDynamicFloat("axisY",0,-1000,1000,"Y Axis","Absolute translation amount along the Y axis"));
        parlst.addParam(new RichDynamicFloat("axisZ",0,-1000,1000,"Z Axis","Absolute translation amount along the Z axis"));
		parlst.addParam(new RichBool("centerFlag",false,"translate viewpoint position to the origin","If selected, the camera viewpoint is translated to the origin"));
		parlst.addParam(new RichBool ("toallRaster", false, "Apply to all Raster layers", "Apply the same scaling to all the Raster layers: it is taken into account only if 'Raster Camera' is selected"));
	    parlst.addParam(new RichBool ("toall", false, "Apply to all Raster and Mesh layers", "Apply the same scaling to all the layers, including any 3D layer"));
	   }
     break;
	
   case FP_CAMERA_TRANSFORM :
	  {
		QStringList shotType;
        shotType.push_back("Raster Camera");
        shotType.push_back("Mesh Camera");
		QStringList behaviour;
        behaviour.push_back("The matrix is the transformation to apply to the extrinsics");
        behaviour.push_back("The matrix represent the new extrinsics");

		vcg::Matrix44f mat; mat.SetIdentity();
	    parlst.addParam(new RichMatrix44f("TransformMatrix",mat,""));
	    parlst.addParam(new RichEnum("camera", 0, shotType, tr("Camera type"), tr("Choose the camera to scale")));
	    parlst.addParam(new RichEnum("behaviour", 0, behaviour, tr("Matrix semantic"), tr("What the matrix is used for")));
		parlst.addParam(new RichBool ("toallRaster", false, "Apply to all Raster layers", "Apply the same scaling to all the Raster layers: it is taken into account only if 'Raster Camera' is selected"));
	    parlst.addParam(new RichBool ("toall", false, "Apply to all Raster and Mesh layers", "Apply the same scaling to all the layers, including any 3D layer"));
	
	   }
     break;  case FP_SET_RASTER_CAMERA :
     parlst.addParam(new RichShotf ("Shot", defShot, "New shot", "This filter allow to set a shot for the current raster."));
     break;

   case FP_SET_MESH_CAMERA :
     parlst.addParam(new RichShotf ("Shot", defShot, "New shot", "This filter allow to set a shot for the current mesh."));
                 break;
   case FP_QUALITY_FROM_CAMERA :
                 parlst.addParam(new RichBool ("Depth", true, "Depth", "Use depth as a factor."));
                 parlst.addParam(new RichBool ("Facing", false, "ViewAngle", "Use cosine of viewing angle as a factor."));
                 parlst.addParam(new RichBool ("Clip", false,  "Clipping", "clip values outside the viewport to zero."));
                 parlst.addParam(new RichBool("normalize",false,"normalize","if checked normalize all quality values in range [0..1]"));
                 parlst.addParam(new RichBool("map",false,"map into color", "if checked map quality generated values into per-vertex color"));
                 break;
   default: break; // do not add any parameter for the other filters
  }
}

// Core Function doing the actual mesh processing.
bool FilterCameraPlugin::applyFilter(QAction *filter, MeshDocument &md, RichParameterSet & par, vcg::CallBackPos */*cb*/)
{
  CMeshO &cm=md.mm()->cm;
  RasterModel *rm = md.rm();
	switch(ID(filter))
  {		
  case FP_CAMERA_ROTATE :
    {
		Matrix44f trRot; trRot.SetIdentity();
        Point3f axis, tranVec;
		Matrix44f trTran,trTranInv;

		switch(par.getEnum("rotAxis"))
		{
			case 0: axis=Point3f(1,0,0); break;
			case 1: axis=Point3f(0,1,0);break;
			case 2: axis=Point3f(0,0,1);break;
			case 3: axis=par.getPoint3f("customAxis");break;
		}
		switch(par.getEnum("rotCenter"))
		{
			case 0: tranVec=Point3f(0,0,0); break;
			case 1: {
					switch(par.getEnum("camera"))
					{
						case 0:     tranVec=rm->shot.Extrinsics.Tra();
							break;
						case 1: 	tranVec=cm.shot.Extrinsics.Tra();
					}
				}
				break;
			case 2: tranVec=par.getPoint3f("customCenter");break;
		}

		float angleDeg= par.getDynamicFloat("angle");
		
		trRot.SetRotateDeg(angleDeg,axis);
		trTran.SetTranslate(tranVec);
		trTranInv.SetTranslate(-tranVec);
		//cm.Tr=trTran*trRot*trTranInv;
		Matrix44f transf=trTran*trRot*trTranInv;
		if (par.getBool("toall"))
		{
			for (int i=0; i<md.meshList.size(); i++)
			{
				md.meshList[i]->cm.Tr=transf;
				tri::UpdatePosition<CMeshO>::Matrix(md.meshList[i]->cm, md.meshList[i]->cm.Tr);
				tri::UpdateNormals<CMeshO>::PerVertexMatrix(md.meshList[i]->cm,md.meshList[i]->cm.Tr);
				tri::UpdateNormals<CMeshO>::PerFaceMatrix(md.meshList[i]->cm,md.meshList[i]->cm.Tr);
				tri::UpdateBounding<CMeshO>::Box(md.meshList[i]->cm);
				md.meshList[i]->cm.Tr.SetIdentity();
				md.meshList[i]->cm.shot.ApplyRigidTransformation(transf);
				
			}
			for (int i=0; i<md.rasterList.size(); i++)
			{
				md.rasterList[i]->shot.ApplyRigidTransformation(transf);
				
			}
		}
		else if (par.getBool("toallRaster") && (par.getEnum("camera")==0))
		{
			for (int i=0; i<md.rasterList.size(); i++)
			{
				md.rasterList[i]->shot.ApplyRigidTransformation(transf);

			}
		}
		else switch(par.getEnum("camera"))
		{	
			case 0: 
				{
				rm->shot.ApplyRigidTransformation(transf);
				}
		   case 1: 
				{		
				cm.shot.ApplyRigidTransformation(transf);
				}
		}
    }
  break;
  case FP_CAMERA_SCALE :
    {
		Matrix44f trScale; trScale.SetIdentity();
		Point3f tranVec;
		Matrix44f trTran,trTranInv;

		float Scale= par.getFloat("scale");
		trScale.SetScale(Scale,Scale,Scale);

		switch(par.getEnum("scaleCenter"))
		{
			case 0: tranVec=Point3f(0,0,0); break;
			case 1: 
				{
					switch(par.getEnum("camera"))
					{
						case 0:     tranVec=rm->shot.Extrinsics.Tra();
							break;
						case 1: 	tranVec=cm.shot.Extrinsics.Tra();
					}
				}
				break;
			case 2: tranVec=par.getPoint3f("customCenter");break;
		}

		trTran.SetTranslate(tranVec);
		trTranInv.SetTranslate(-tranVec);
		if (par.getBool("toall"))
		{
			for (int i=0; i<md.meshList.size(); i++)
			{
				md.meshList[i]->cm.Tr=trTran*trScale*trTranInv;
				tri::UpdatePosition<CMeshO>::Matrix(md.meshList[i]->cm, md.meshList[i]->cm.Tr);
				tri::UpdateNormals<CMeshO>::PerVertexMatrix(md.meshList[i]->cm,md.meshList[i]->cm.Tr);
				tri::UpdateNormals<CMeshO>::PerFaceMatrix(md.meshList[i]->cm,md.meshList[i]->cm.Tr);
				tri::UpdateBounding<CMeshO>::Box(md.meshList[i]->cm);
				md.meshList[i]->cm.Tr.SetIdentity();
				md.meshList[i]->cm.shot.ApplyRigidTransformation(trTran);
				md.meshList[i]->cm.shot.RescalingWorld(trScale[0][0], false);
				md.meshList[i]->cm.shot.ApplyRigidTransformation(trTranInv);

			}
			for (int i=0; i<md.rasterList.size(); i++)
			{
				md.rasterList[i]->shot.ApplyRigidTransformation(trTran);
				md.rasterList[i]->shot.RescalingWorld(trScale[0][0], false);
				md.rasterList[i]->shot.ApplyRigidTransformation(trTranInv);
			}
		}
		else if (par.getBool("toallRaster") && (par.getEnum("camera")==0))
		{
			for (int i=0; i<md.rasterList.size(); i++)
			{
				md.rasterList[i]->shot.ApplyRigidTransformation(trTran);
				md.rasterList[i]->shot.RescalingWorld(trScale[0][0], false);
				md.rasterList[i]->shot.ApplyRigidTransformation(trTranInv);
			}
		}
		else switch(par.getEnum("camera"))
		{	
			case 0: 
				{
				rm->shot.ApplyRigidTransformation(trTran);
				rm->shot.RescalingWorld(Scale, false);
				rm->shot.ApplyRigidTransformation(trTranInv);
				}
		   case 1: 
				{		
				cm.shot.ApplyRigidTransformation(trTran);
				cm.shot.RescalingWorld(Scale, false);
				cm.shot.ApplyRigidTransformation(trTranInv);
				}
		}
    }
  break;
  case FP_CAMERA_TRANSLATE :
    {
		Matrix44f trTran; trTran.SetIdentity();

		float xScale= par.getDynamicFloat("axisX");
		float yScale= par.getDynamicFloat("axisY");
		float zScale= par.getDynamicFloat("axisZ");

		trTran.SetTranslate(xScale,yScale,zScale);
		if(par.getBool("centerFlag"))
			switch(par.getEnum("camera"))
					{
						case 0:     trTran.SetTranslate(-rm->shot.Extrinsics.Tra());
							break;
						case 1: 	trTran.SetTranslate(-cm.shot.Extrinsics.Tra());
					}

		if (par.getBool("toall"))
		{
			for (int i=0; i<md.meshList.size(); i++)
			{
				md.meshList[i]->cm.Tr=trTran;
				tri::UpdatePosition<CMeshO>::Matrix(md.meshList[i]->cm, md.meshList[i]->cm.Tr);
				tri::UpdateNormals<CMeshO>::PerVertexMatrix(md.meshList[i]->cm,md.meshList[i]->cm.Tr);
				tri::UpdateNormals<CMeshO>::PerFaceMatrix(md.meshList[i]->cm,md.meshList[i]->cm.Tr);
				tri::UpdateBounding<CMeshO>::Box(md.meshList[i]->cm);
				md.meshList[i]->cm.Tr.SetIdentity();
				md.meshList[i]->cm.shot.ApplyRigidTransformation(trTran);
				
			}
			for (int i=0; i<md.rasterList.size(); i++)
			{
				md.rasterList[i]->shot.ApplyRigidTransformation(trTran);
				
			}
		}
		else if (par.getBool("toallRaster") && (par.getEnum("camera")==0))
		{
			for (int i=0; i<md.rasterList.size(); i++)
			{
				md.rasterList[i]->shot.ApplyRigidTransformation(trTran);

			}
		}
		else switch(par.getEnum("camera"))
		{	
			case 0: 
				{
				rm->shot.ApplyRigidTransformation(trTran);
				}
		   case 1: 
				{		
				cm.shot.ApplyRigidTransformation(trTran);
				}
		}
    }
  break;
  case FP_CAMERA_TRANSFORM :
	  {
		vcg::Matrix44f mat,inv; 
		inv.SetIdentity();
		vcg::Point3f tra;
	   	mat = par.getMatrix44("TransformMatrix"); 
		if(par.getEnum("behaviour") == 1){
			inv = rm->shot.Extrinsics.Rot();
			tra =  inv * rm->shot.Extrinsics.Tra();
			inv[0][3] = -tra[0];
			inv[1][3] = -tra[1];
			inv[2][3] = -tra[2];
			mat = mat * inv;
			mat = inv;
		}

	  if (par.getBool("toall"))
	  {
			for (int i=0; i<md.meshList.size(); i++)
			{
				md.meshList[i]->cm.Tr = mat;
				tri::UpdatePosition<CMeshO>::Matrix(md.meshList[i]->cm, md.meshList[i]->cm.Tr);
				tri::UpdateNormals<CMeshO>::PerFaceMatrix(md.meshList[i]->cm,md.meshList[i]->cm.Tr);
				tri::UpdateBounding<CMeshO>::Box(md.meshList[i]->cm);
				md.meshList[i]->cm.Tr.SetIdentity();
				md.meshList[i]->cm.shot.ApplySimilarity(mat);
				
			}
			for (int i=0; i<md.rasterList.size(); i++)
			{
				md.rasterList[i]->shot.ApplySimilarity(mat);
				
			}
		}
		else if (par.getBool("toallRaster") && (par.getEnum("camera")==0))
		{
			for (int i=0; i<md.rasterList.size(); i++)
			{
				md.rasterList[i]->shot.ApplySimilarity(mat);

			}
		}
		else switch(par.getEnum("camera"))
		{	
			case 0: 
				{
				rm->shot.ApplyRigidTransformation(mat);
				}
		   case 1: 
				{		
				cm.shot.ApplyRigidTransformation(mat);
				}
		}
	  }

  break;

  case FP_SET_RASTER_CAMERA :
	  {
			vcg::Shotf shotGot=par.getShotf("Shot");
			rm->shot = shotGot;
			float ratio=(float)rm->currentPlane->image.height()/(float)shotGot.Intrinsics.ViewportPx[1];
			rm->shot.Intrinsics.ViewportPx[0]=rm->currentPlane->image.width();
			rm->shot.Intrinsics.ViewportPx[1]=rm->currentPlane->image.height();
			rm->shot.Intrinsics.PixelSizeMm[1]/=ratio;
			rm->shot.Intrinsics.PixelSizeMm[0]/=ratio;
			rm->shot.Intrinsics.CenterPx[0]=(int)((float)rm->shot.Intrinsics.ViewportPx[0]/2.0);
			rm->shot.Intrinsics.CenterPx[1]=(int)((float)rm->shot.Intrinsics.ViewportPx[1]/2.0);
	  }
  break;
    case FP_SET_MESH_CAMERA :
      cm.shot = par.getShotf("Shot");
    break;
    case FP_QUALITY_FROM_CAMERA :
      {
        if(!cm.shot.IsValid())
        {
          this->errorMessage="Mesh has not a valid camera";
          return false;
        }
        md.mm()->updateDataMask(MeshModel::MM_VERTQUALITY + MeshModel::MM_VERTCOLOR);
        bool clipFlag = par.getBool("Clip");
        bool depthFlag = par.getBool("Depth");
        bool facingFlag = par.getBool("Facing");
        CMeshO::VertexIterator vi;
        float deltaN = cm.bbox.Diag()/100.0f;
        for(vi=cm.vert.begin();vi!=cm.vert.end();++vi)
          {
            Point2f pp = cm.shot.Project( (*vi).P());
            float depth = cm.shot.Depth((*vi).P());
            Point3f pc = cm.shot.ConvertWorldToCameraCoordinates((*vi).P());
            Point3f pn = cm.shot.ConvertWorldToCameraCoordinates((*vi).P()+(*vi).N()*deltaN);
            float q=1.0;

            if(depthFlag) q*=depth;
            if(facingFlag) q*=pn[2]-pc[2];
            if(clipFlag)
            {
              if(pp[0]<0 || pp[1]<0 ||
                 pp[0]>cm.shot.Intrinsics.ViewportPx[0] || pp[1]>cm.shot.Intrinsics.ViewportPx[1])
                  q=0;
            }
            (*vi).Q() = q;
           }
        if(par.getBool("normalize")) tri::UpdateQuality<CMeshO>::VertexNormalize(cm);
        if(par.getBool("map")) tri::UpdateColor<CMeshO>::VertexQualityRamp(cm);

      }
    break;
  }

	return true;
}

int FilterCameraPlugin::postCondition(QAction * filter) const
{
  switch (ID(filter))
  {
    case FP_SET_MESH_CAMERA :
	case FP_CAMERA_ROTATE   : 	
	case FP_CAMERA_TRANSLATE   :               
	case FP_CAMERA_TRANSFORM:
	case FP_CAMERA_SCALE                  : return MeshModel::MM_CAMERA;
    case FP_QUALITY_FROM_CAMERA           : return MeshModel::MM_VERTQUALITY + MeshModel::MM_VERTCOLOR;
    default                  : return MeshModel::MM_UNKNOWN;
  }
}

 FilterCameraPlugin::FilterClass FilterCameraPlugin::getClass(QAction *a)
{
  switch(ID(a))
  {
  case FP_CAMERA_ROTATE :
  case FP_CAMERA_SCALE :
  case FP_CAMERA_TRANSLATE :
  case FP_CAMERA_EDIT :
  case FP_CAMERA_TRANSFORM:
  case FP_SET_MESH_CAMERA :
  case FP_QUALITY_FROM_CAMERA :
      return MeshFilterInterface::Camera;
  case FP_SET_RASTER_CAMERA :
	  return FilterClass (MeshFilterInterface::Camera + MeshFilterInterface::RasterLayer) ;



  }
  assert(0);
}

Q_EXPORT_PLUGIN(FilterCameraPlugin)