Skip to Content.
Sympa Menu

cgal-discuss - Re: [cgal-discuss] Copying two different triangulation types.

Subject: CGAL users discussion list

List archive

Re: [cgal-discuss] Copying two different triangulation types.


Chronological Thread 
  • From: Simon Perkins <>
  • To:
  • Subject: Re: [cgal-discuss] Copying two different triangulation types.
  • Date: Thu, 28 Jan 2010 12:03:16 +0200
  • Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; b=gpgvoWcwI3Pqni24BeYyHXhYQfay5zQ+aNMbsHax9SNDOpj0/V7k37NyEXfjuVZWv0 lXhUOuGtF6CnodAHGwKcOhacW4XBObZMKMSkG7l7983+DP2EXER4f5hEd4UOzz2SYy2l 6rjwiQFOA1bQ/AJd8ix8VgTtdA4H80XSKirRY=

Thanks Sebastien, the code snippet works well.

Sylvain, you're correct that I could extend the Triangulation associated with the Mesh_3. My project was originally based on the Delaunay_triangulation_3 class in CGAL 3.4 and I wanted avoided refactoring at this point. But, I did want to try out Mesh_3 package in CGAL 3.5.1 to generate and use some random meshes.

With regard to the failed assertion, the following is produced when I try and read a triangulation from an ifstream

terminate called after throwing an instance of 'CGAL::Assertion_exception'
  what():  CGAL ERROR: assertion violation!
Expr: false
File: /home/simon/usr/local/include/CGAL/Triangulation_data_structure_3.h
Line: 2651

I've attached my current test program that produces it - its modified from the mesh_implicit_sphere.cpp example to mesh an implicit cube. I've also attached the output triangulation file.

regards
  Simon

On Thu, Jan 28, 2010 at 10:36 AM, Sylvain Pion <> wrote:
Le 28/01/10 08:50, Simon Perkins a écrit :

Dear All

Is it possible to perform an exact copy of the vertices and cells
between two different 3D Triangulation types? For example, I want to use
the Mesh_3 package to tetrahedralize a domain and then copy the Mesh_3
Triangulation into a customized Triangulation_3.

What is the problem ?  Is it different point type, or different requirements
in the vertex/cell types ?  In the latter case, it might also be possible
to combine the requirements on vertex/cell types in order to have one
triangulation type that works in both cases.  Then you avoid the copy
completely.


 It doesn't seem
possible to do this via the constructor, copy() and swap() functions. I
also attempted this with the output and input streams, by outputting a
Mesh_3 Triangulation and trying to input the same into a
Triangulation_3, but this did not work due to a failed assertion.

"a failed assertion" ?

--
Sylvain Pion
INRIA Sophia Antipolis
Geometrica Project-Team
CGAL, http://cgal.org/


--
You are currently subscribed to cgal-discuss.
To unsubscribe or access the archives, go to
https://lists-sop.inria.fr/wws/info/cgal-discuss


/*
 * main.cpp
 *
 *  Created on: 21 Jan 2010
 *      Author: simon
 */

#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>

#include <CGAL/Mesh_triangulation_3.h>
#include <CGAL/Mesh_complex_3_in_triangulation_3.h>
#include <CGAL/Mesh_criteria_3.h>

#include <CGAL/Implicit_mesh_domain_3.h>
#include <CGAL/make_mesh_3.h>

#include <CGAL/IO/Geomview_stream.h>
#include <CGAL/IO/Triangulation_geomview_ostream_3.h>

#include <CGAL/Triangulation_3.h>

typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef K::FT FT;
typedef K::Point_3 Point_3;
typedef FT(Function)(const Point_3 &);
typedef CGAL::Implicit_mesh_domain_3<Function, K> Mesh_domain;

typedef CGAL::Mesh_triangulation_3<Mesh_domain>::type Tr;
typedef CGAL::Mesh_complex_3_in_triangulation_3<Tr> C3t3;

typedef CGAL::Mesh_criteria_3<Tr> Mesh_criteria;
typedef Mesh_criteria::Facet_criteria Facet_criteria;
typedef Mesh_criteria::Cell_criteria Cell_criteria;

FT cube_function(const Point_3 & p)
{
	if(0.0f <= p.x() && p.x() <= 1.0 &&
	   0.0f <= p.y() && p.y() <= 1.0 &&
	   0.0f <= p.z() && p.z() <= 1.0)
	{
		return -1.0f;
	}

	return 1.0f;
}

//build our internal TDS using the TDS of an already built triangulation
//returns the number of vertices
template <class TDS_src,class TDS_tgt>
void
copy_tds(const TDS_src& src,TDS_tgt& tgt,typename TDS_src::Vertex_handle s_infinite,typename TDS_tgt::Vertex_handle t_infinite)
{
  int n = src.number_of_vertices();
  if (n == 0)  return;
  tgt.cells().clear();
  tgt.set_dimension(src.dimension());

  // Number of pointers to cell/vertex to copy per cell.
  int dim = (std::max)(1, tgt.dimension() + 1);

  // Create the vertices.
  std::vector<typename TDS_src::Vertex_handle> TV(n);
  int i = 0;

  for (typename TDS_src::Vertex_iterator vit = src.vertices_begin();
       vit != src.vertices_end(); ++vit)
    TV[i++] = vit;

  CGAL_triangulation_assertion( i == n );

  std::map< typename TDS_src::Vertex_handle, typename TDS_tgt::Vertex_handle > V;
  std::map< typename TDS_src::Cell_handle, typename TDS_tgt::Cell_handle > F;

  assert(TV[0]==s_infinite);
  assert(tgt.vertices_begin()==t_infinite);
  V[ TV[0] ] = t_infinite;
  for (i=1; i <= n-1; ++i){
    typename TDS_tgt::Vertex_handle vh=
      tgt.create_vertex( typename TDS_tgt::Vertex(TV[i]->point()) );
    V[ TV[i] ] = vh;
  }

  // Create the cells.
  for (typename TDS_src::Cell_iterator cit = src.cells_begin();
          cit != src.cells_end(); ++cit) {
      //WE ARE LOOSING ALL INFO INSIDE CELL (HIDDEN POINT ETC...)
      F[cit] = tgt.create_cell();
      for (int j = 0; j < dim; j++)
        F[cit]->set_vertex(j, V[cit->vertex(j)] );
  }

  // Link the vertices to a cell.
  for (typename TDS_src::Vertex_iterator vit2 = src.vertices_begin();
       vit2 != src.vertices_end(); ++vit2)
    V[vit2]->set_cell( F[vit2->cell()] );

  // Hook neighbor pointers of the cells.
  for (typename TDS_src::Cell_iterator cit2 = src.cells_begin();
          cit2 != src.cells_end(); ++cit2) {
    for (int j = 0; j < dim; j++)
      F[cit2]->set_neighbor(j, F[cit2->neighbor(j)] );
  }

  CGAL_triangulation_postcondition( tgt.is_valid() );
}

int main(int argc, char * argv[])
{
	Mesh_domain domain(cube_function, K::Sphere_3(CGAL::ORIGIN, 2.0f));

	  // Criteria
	Facet_criteria facet_criteria(30, 0.25, 0.05); // angle, size, approximation
	Cell_criteria cell_criteria(3, 0.25); // radius-edge ratio, size
	Mesh_criteria criteria(facet_criteria, cell_criteria);
	CGAL::Geomview_stream gs;
	char ch;

	C3t3 c3t3(CGAL::make_mesh_3<C3t3>(domain, criteria));

	std::cout << "Triangulation Statistics" << std::endl;
	std::cout << c3t3.triangulation().number_of_vertices() << " vertices." << std::endl;
	std::cout << c3t3.triangulation().number_of_cells() << " cells." << std::endl;

	gs.set_wired(true);
	gs << c3t3.triangulation();
	std::cin >> ch;

	gs.clear();

	typedef CGAL::Triangulation_3<K> Triangulation_3;
	Triangulation_3 triangulation;

	copy_tds(
		c3t3.triangulation().tds(), triangulation.tds(),
		c3t3.triangulation().infinite_vertex(),
		triangulation.infinite_vertex());

	std::cout << "Triangulation Statistics" << std::endl;
	std::cout << triangulation.number_of_vertices() << " vertices." << std::endl;
	std::cout << triangulation.number_of_cells() << " cells." << std::endl;

	gs << triangulation;
	std::cin >> ch;

	{
		std::ofstream output("tri.out");
		output << c3t3.triangulation();
	}

	triangulation.clear();

	{
		std::ifstream input("tri.out");
		input >> triangulation;
	}
}

Attachment: tri.out
Description: Binary data




Archive powered by MHonArc 2.6.16.

Top of Page