[Insight-users] RE: [vtkusers] OpenMesh + VTK + QT ? Please Help !!!!

Toon Huysmans denhuys at hotmail.com
Wed Oct 12 06:26:32 EDT 2005


Skipped content of type multipart/alternative-------------- next part --------------
/*=========================================================================

Program:   Visualization Toolkit
Module:    $RCSfile: vtkCubeSource.cxx,v $
Language:  C++
Date:      $Date: 2002/12/17 02:05:38 $
Version:   $Revision: 1.48 $

Copyright (c) 1993-2002 Ken Martin, Will Schroeder, Bill Lorensen 
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.

This software is distributed WITHOUT ANY WARRANTY; without even 
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
PURPOSE.  See the above copyright notice for more information.

=========================================================================*/
#define __vtkOpenMeshSource_cpp

#include "vtkOpenMeshSource.h"

#include "vtkCellArray.h"
#include "vtkFloatArray.h"
#include "vtkObjectFactory.h"
#include "vtkPointData.h"
#include "vtkPoints.h"
#include "vtkPolyData.h"

#include <OpenMesh/Core/Utils/GenProg.hh>

template <class MeshT>
vtkOpenMeshSource<MeshT>* vtkOpenMeshSource<MeshT>::New() 
{ 		
	return new vtkOpenMeshSource<MeshT>; 
} 

template <class MeshT>
vtkOpenMeshSource<MeshT>::vtkOpenMeshSource()
{
}

template <class MeshT>
void 
vtkOpenMeshSource<MeshT>::Execute()
{
	cout << "Entering Execute vtkOpenMeshSource" << endl;

	bool hasTexCoords = fMesh->has_vertex_texcoords();

	int numTris = fMesh->n_faces();
	int numPts = fMesh->n_vertices();
	
	vtkIdType pts[3];
	vtkPoints *newPoints; 
	vtkCellArray *newTris;
	vtkPolyData *output = this->GetOutput();

	//vertices
	newPoints = vtkPoints::New();
	newPoints->Allocate(numPts);

	//triangles
	newTris = vtkCellArray::New();
	newTris->Allocate(newTris->EstimateSize(numTris,3));

	//texture coordinates
	vtkFloatArray *newTCoords = vtkFloatArray::New();
	newTCoords->SetNumberOfComponents(2);
	newTCoords->Allocate(numPts);
	newTCoords->SetName("TCoords");

	//
	// Generate points
	//
	MeshT::VertexIter v_it, v_end(fMesh->vertices_end());
    for (v_it = fMesh->vertices_begin(); v_it!=v_end; ++v_it)
	{		
		newPoints->InsertNextPoint(fMesh->point( v_it ));
		if (hasTexCoords)
		{		
			newTCoords->InsertNextTuple(fMesh->texcoord( v_it ));
		}
	}
	
	//Add triangles
	MeshT::FaceIter f_it, f_end(fMesh->faces_end());
    for (f_it = fMesh->faces_begin(), f_it.enable_skipping(); f_it!=f_end; ++f_it)
	{	
		
		MeshT::FVIter fvIt = fMesh->fv_iter(f_it);
		pts[0] = fvIt.handle().idx(); ++fvIt;
		pts[1] = fvIt.handle().idx(); ++fvIt;
		pts[2] = fvIt.handle().idx();
		newTris->InsertNextCell(3,pts);
	}

	

	// Update ourselves and release memory

	output->SetPoints(newPoints);
	newPoints->Delete();

	if (hasTexCoords) 
	{
		output->GetPointData()->SetTCoords(newTCoords);
	}
	newTCoords->Delete();
	
	output->SetPolys(newTris);
	newTris->Delete();
	
	cout << "Leaving Execute vtkOpenMeshSource" << endl;
}

-------------- next part --------------
/*=========================================================================

  Program:   Visualization Toolkit
  Module:    $RCSfile: vtkOpenMeshSource.h,v $
  Language:  C++
  Date:      $Date: 2004/06/15 15:29:13 $
  Version:   $Revision: 0.1 $

  Copyright (c) 1993-2002 Ken Martin, Will Schroeder, Bill Lorensen 
  All rights reserved.
  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.

     This software is distributed WITHOUT ANY WARRANTY; without even 
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
     PURPOSE.  See the above copyright notice for more information.

=========================================================================*/
// .NAME vtkOpenMeshSource - create a polygonal representation of a openmesh datastructure
// .SECTION Description
// vtkOpenMeshSource creates a polygonal representation of a openmesh datastructure
// it is templated with the mesh type

#ifndef __vtkOpenMeshSource_h
#define __vtkOpenMeshSource_h

#include "vtkPolyDataSource.h"

template <class MeshT>
class vtkOpenMeshSource : public vtkPolyDataSource 
{
public:
  static vtkOpenMeshSource *New();  

  void SetMesh(MeshT &mesh){fMesh = &mesh;}
    
protected:
  vtkOpenMeshSource();
  ~vtkOpenMeshSource() {};

  void Execute();  

  MeshT *fMesh;

private:
  vtkOpenMeshSource(const vtkOpenMeshSource&);  // Not implemented.
  void operator=(const vtkOpenMeshSource&);  // Not implemented.
};


#if !defined(__vtkOpenMeshSource_cpp)
#define __vtkOpenMeshSource_cpp
#include "vtkOpenMeshSource.cxx"
#endif

#endif // __vtkOpenMeshSource_h




More information about the Insight-users mailing list