Ejemplo n.º 1
0
int main()
{
  // Domain
  CGAL::Image_3 image;
  image.read("data/liver.inr.gz");
  Mesh_domain domain(image);

  // Mesh criteria
  Mesh_criteria criteria(facet_angle=30, facet_size=5, facet_distance=1.5,
                         cell_radius_edge_ratio=2, cell_size=7);

  // Mesh generation and optimization in one call (sliver_bound is the
  // targeted dihedral angle in degree)
  C3t3 c3t3 = CGAL::make_mesh_3<C3t3>(domain, criteria,
                                      no_exude(),
                                      perturb(sliver_bound=10, time_limit=15));
  
  // Mesh generation and optimization in several call
  C3t3 c3t3_bis = CGAL::make_mesh_3<C3t3>(domain, criteria,
                                          no_perturb(), no_exude());
  
  CGAL::perturb_mesh_3(c3t3_bis, domain, time_limit=15);

  // Output
  std::ofstream medit_file("out.mesh");
  c3t3.output_to_medit(medit_file);
  
  std::ofstream medit_file_bis("out_bis.mesh");
  c3t3_bis.output_to_medit(medit_file_bis);

  return 0;
}
Ejemplo n.º 2
0
int main()
{
  // Loads image
  CGAL::Image_3 image;
  image.read("data/liver.inr.gz");

  // Domain
  Mesh_domain domain(image);

  // Sizing field: set global size to 8 and kidney size (label 127) to 3
  double kidney_size = 3.;
  int volume_dimension = 3;
  Sizing_field size(8);
  size.set_size(kidney_size, volume_dimension, 
                domain.index_from_subdomain_index(127));
  
  // Mesh criteria
  Mesh_criteria criteria(facet_angle=30, facet_size=6, facet_distance=2,
                         cell_radius_edge_ratio=3, cell_size=size);

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

  // Output
  std::ofstream medit_file("out.mesh");
  c3t3.output_to_medit(medit_file);

  return 0;
}
Ejemplo n.º 3
0
int main(int argc, char* argv[])
{
  /// [Loads image]
  const char* fname = (argc>1)?argv[1]:"data/liver.inr.gz";
  CGAL::Image_3 image;
  if(!image.read(fname)){
    std::cerr << "Error: Cannot read file " <<  fname << std::endl;
    return EXIT_FAILURE;
  }
  /// [Loads image]

  // Domain
  Mesh_domain domain(image);

  // Mesh criteria
  Mesh_criteria criteria(facet_angle=30, facet_size=6, facet_distance=4,
                         cell_radius_edge_ratio=3, cell_size=8);

  /// [Meshing]
  C3t3 c3t3 = CGAL::make_mesh_3<C3t3>(domain, criteria);
  /// [Meshing]

  // Output
  std::ofstream medit_file("out.mesh");
  c3t3.output_to_medit(medit_file);

  return 0;
}
int main()
{
  // Domain
  CGAL::Image_3 image;
  image.read("data/liver.inr.gz");
  Mesh_domain domain(image);

  // Mesh criteria
  Mesh_criteria criteria(facet_angle=30, facet_distance=1.2,
                         cell_radius_edge_ratio=2);

  // Mesh generation and optimization in one call
  C3t3 c3t3 = CGAL::make_mesh_3<C3t3>(domain, criteria,
                                      lloyd(time_limit=30),
                                      no_perturb(),
                                      exude(time_limit=10, sliver_bound=10));
  
  // Mesh generation and optimization in several call
  C3t3 c3t3_bis = CGAL::make_mesh_3<C3t3>(domain, criteria,
                                          no_perturb(), no_exude());
  
  CGAL::lloyd_optimize_mesh_3(c3t3_bis, domain, time_limit=30);
  CGAL::exude_mesh_3(c3t3_bis, sliver_bound=10, time_limit=10);
  
  // Output
  std::ofstream medit_file("out.mesh");
  c3t3.output_to_medit(medit_file);
  
  std::ofstream medit_file_bis("out_bis.mesh");
  c3t3_bis.output_to_medit(medit_file_bis);

  return 0;
}
Ejemplo n.º 5
0
int main(int argc, char* argv[])
{
  const char* fname = (argc>1)?argv[1]:"data/liver.inr.gz";
  // Loads image
  CGAL::Image_3 image;
  if(!image.read(fname)){
    std::cerr << "Error: Cannot read file " <<  fname << std::endl;
    return EXIT_FAILURE;
  }

  // Domain
  Mesh_domain domain = Mesh_domain::create_labeled_image_mesh_domain(image);

  // Sizing field: set global size to 8 and kidney size (label 127) to 3
  double kidney_size = 3.;
  int volume_dimension = 3;
  Sizing_field size(8);
  size.set_size(kidney_size, volume_dimension, 
                domain.index_from_subdomain_index(127));
  
  // Mesh criteria
  Mesh_criteria criteria(facet_angle=30, facet_size=6, facet_distance=2,
                         cell_radius_edge_ratio=3, cell_size=size);

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

  // Output
  std::ofstream medit_file("out.mesh");
  c3t3.output_to_medit(medit_file);

  return 0;
}
Ejemplo n.º 6
0
int main()
{
    // Loads image
    CGAL::Image_3 image;
    image.read ( "p.bmp" );
    // Domain
    Mesh_domain domain ( image );
    // Mesh criteria
    Mesh_criteria criteria ( facet_angle=30, facet_size=6, facet_distance=4,
                             cell_radius_edge_ratio=3, cell_size=8 );
    // Meshing
    C3t3 c3t3 = CGAL::make_mesh_3<C3t3> ( domain, criteria );
    // Output
    std::ofstream medit_file ( "out.mesh" );
    c3t3.output_to_medit ( medit_file );
    return 0;
}
Ejemplo n.º 7
0
int main()
{
  // Loads image
  CGAL::Image_3 image;
  if(!image.read("data/skull_2.9.inr")) return 1;

  // Domain
  Mesh_domain domain(image, std::bind1st(std::less<Image_word_type>(), 2.9f), 0.f);

  // Mesh criteria
  Mesh_criteria criteria(facet_angle=30, facet_size=6, facet_distance=2,
                         cell_radius_edge_ratio=3, cell_size=8);

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

  // Output
  std::ofstream medit_file("out.mesh");
  c3t3.output_to_medit(medit_file);

  return 0;
}
int main(int argc, char*argv[])
{
  const char* fname = (argc>1)?argv[1]:"data/liver.inr.gz";
  // Domain
  CGAL::Image_3 image;
  if(!image.read(fname)){
    std::cerr << "Error: Cannot read file " <<  fname << std::endl;
    return EXIT_FAILURE;
  }
  Mesh_domain domain = Mesh_domain::create_labeled_image_mesh_domain(image);

  // Mesh criteria
  Mesh_criteria criteria(facet_angle=30, facet_distance=1.2,
                         cell_radius_edge_ratio=2);

  // Mesh generation and optimization in one call
  C3t3 c3t3 = CGAL::make_mesh_3<C3t3>(domain, criteria,
                                      lloyd(time_limit=30),
                                      no_perturb(),
                                      exude(time_limit=10, sliver_bound=10));
  
  // Mesh generation and optimization in several call
  C3t3 c3t3_bis = CGAL::make_mesh_3<C3t3>(domain, criteria,
                                          no_perturb(), no_exude());
  
  CGAL::lloyd_optimize_mesh_3(c3t3_bis, domain, time_limit=30);
  CGAL::exude_mesh_3(c3t3_bis, sliver_bound=10, time_limit=10);
  
  // Output
  std::ofstream medit_file("out.mesh");
  c3t3.output_to_medit(medit_file);
  
  std::ofstream medit_file_bis("out_bis.mesh");
  c3t3_bis.output_to_medit(medit_file_bis);

  return 0;
}
Ejemplo n.º 9
0
int main(int argc, char* argv[])
{
  const char* fname = (argc>1)?argv[1]:"data/420.inr";
  // Loads image
  CGAL::Image_3 image;
  if(!image.read(fname)){
    std::cerr << "Error: Cannot read file " <<  fname << std::endl;
    return EXIT_FAILURE;
  }

  // Domain
  Mesh_domain domain(image);

  /// Declare 1D-features, see above [Call add_1D_features]
  const char* lines_fname = (argc>2)?argv[2]:"data/420.polylines.txt";

  if(!add_1D_features(image, domain, lines_fname)) {
    return EXIT_FAILURE;
  }
  /// [Call add_1D_features]

  /// Note that `edge_size` is needed with 1D-features [Mesh criteria]
  Mesh_criteria criteria(edge_size=6,
                         facet_angle=30, facet_size=6, facet_distance=4,
                         cell_radius_edge_ratio=3, cell_size=8);
  /// [Mesh criteria]

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

  // Output
  std::ofstream medit_file("out.mesh");
  c3t3.output_to_medit(medit_file);

  return 0;
}
Ejemplo n.º 10
0
int main(int argc, char** argv)
{
  QApplication app(argc, argv);

  if(argc != 3)
    usage_and_exit(argv[0]);

  QVTKWidget widget;
  widget.resize(256,256);
 
#if QT_VERSION < 0x040000
  app.setMainWidget(&widget);
#endif

  CGAL::Image_3 image;
  if(!image.read(argv[1]))
  {
    std::cerr << "Cannot read image file \"" << argv[1] << "\"!\n";
    usage_and_exit(argv[0]);
  }

  std::stringstream argv2;
  argv2 << argv[2];
  double isovalue;
  if(!(argv2 >> isovalue))
  {
    std::cerr << "Invalid iso-value \"" << argv[2] << "\"!\n";
    usage_and_exit(argv[0]);
  }

  vtkImageData* vtk_image = CGAL::vtk_image_sharing_same_data_pointer(image);

  vtkRenderer *aRenderer = vtkRenderer::New();
  vtkRenderWindow *renWin = vtkRenderWindow::New();
    renWin->AddRenderer(aRenderer);

  widget.SetRenderWindow(renWin);

  vtkContourFilter *skinExtractor = vtkContourFilter::New();
    skinExtractor->SetInputData(vtk_image);
    skinExtractor->SetValue(0, isovalue);
//     skinExtractor->SetComputeNormals(0);
  vtkPolyDataNormals *skinNormals = vtkPolyDataNormals::New();
    skinNormals->SetInputConnection(skinExtractor->GetOutputPort());
    skinNormals->SetFeatureAngle(60.0);
  vtkPolyDataMapper *skinMapper = vtkPolyDataMapper::New();
    skinMapper->SetInputConnection(skinExtractor->GetOutputPort());
    skinMapper->ScalarVisibilityOff();
  vtkActor *skin = vtkActor::New();
    skin->SetMapper(skinMapper);

  // An outline provides context around the data.
  //
  vtkOutlineFilter *outlineData = vtkOutlineFilter::New();
    outlineData->SetInputData(vtk_image);
  vtkPolyDataMapper *mapOutline = vtkPolyDataMapper::New();
    mapOutline->SetInputConnection(outlineData->GetOutputPort());
  vtkActor *outline = vtkActor::New();
    outline->SetMapper(mapOutline);
    outline->GetProperty()->SetColor(0,0,0);

  // It is convenient to create an initial view of the data. The FocalPoint
  // and Position form a vector direction. Later on (ResetCamera() method)
  // this vector is used to position the camera to look at the data in
  // this direction.
  vtkCamera *aCamera = vtkCamera::New();
    aCamera->SetViewUp (0, 0, -1);
    aCamera->SetPosition (0, 1, 0);
    aCamera->SetFocalPoint (0, 0, 0);
    aCamera->ComputeViewPlaneNormal();

  // Actors are added to the renderer. An initial camera view is created.
  // The Dolly() method moves the camera towards the FocalPoint,
  // thereby enlarging the image.
  aRenderer->AddActor(outline);
  aRenderer->AddActor(skin);
  aRenderer->SetActiveCamera(aCamera);
  aRenderer->ResetCamera ();
  aCamera->Dolly(1.5);

  // Set a background color for the renderer and set the size of the
  // render window (expressed in pixels).
  aRenderer->SetBackground(1,1,1);
  renWin->SetSize(640, 480);

  // Note that when camera movement occurs (as it does in the Dolly()
  // method), the clipping planes often need adjusting. Clipping planes
  // consist of two planes: near and far along the view direction. The 
  // near plane clips out objects in front of the plane; the far plane
  // clips out objects behind the plane. This way only what is drawn
  // between the planes is actually rendered.
  aRenderer->ResetCameraClippingRange ();

  // Initialize the event loop and then start it.
//   iren->Initialize();
//   iren->Start(); 

  // It is important to delete all objects created previously to prevent
  // memory leaks. In this case, since the program is on its way to
  // exiting, it is not so important. But in applications it is
  // essential.
  vtk_image->Delete();
  skinExtractor->Delete();
  skinNormals->Delete();
  skinMapper->Delete();
  skin->Delete();
  outlineData->Delete();
  mapOutline->Delete();
  outline->Delete();
  aCamera->Delete();
//   iren->Delete();
  renWin->Delete();
  aRenderer->Delete();

  widget.show();

  app.exec();
  
  return 0;
}
Ejemplo n.º 11
0
int main()
{
  // Loads image
  CGAL::Image_3 image;

  // Read input file with parameters
  Input p;
  p.load_file_elliptic_electrodes();
  

  // Reading image file
  std::cout<<"\n Reading the Image file... ";
  image.read("input.inr");
  
  // Domain
  Mesh_domain domain(image);
  
  //Define Sizing field
  Point or(image.vx () * image.xdim ()/2,
		   image.vy () * image.ydim ()/2, 
		   image.vz () * image.zdim ()/2); //origin

  FILE *F;
  try { F=fopen("electrodes_human.txt","r");}
  catch (exception& e) { cout << e.what() << endl;}
  
  sizing_field_elliptic_electrodes size_e (or,F,image.vx(),image.vy(),image.vz());
  if (F!=NULL) fclose(F);

  size_e.coarse_size=p.ccs;
  size_e.fine_size=p.cs;
  size_e.preserve=p.pres; //Elliptic
  size_e.e_R=p.e_R; //2* to secure fit of the electrode
  size_e.electrode_size=p.e_size;//Planar gradient with electrodes -- size of the mesh near electrodes
        
  // Mesh criteria: faces and cells
  Mesh_criteria criteria(facet_angle=p.fa, facet_size=size_e, facet_distance=p.fd,
                         cell_radius_edge_ratio=p.cre, cell_size=size_e);
  

  // Meshing
  std::cout<<"\n Meshing with initial mesh...";

  C3t3 c3t3= CGAL::make_mesh_3<C3t3>(domain, criteria, CGAL::parameters::features(domain), 
						CGAL::parameters::no_lloyd(), CGAL::parameters::no_odt(), 
						CGAL::parameters::no_perturb(),CGAL::parameters::no_exude()); 

	  
  //Optimisation
  std::cout<<"\n Optimising: ";
  if (p.if_perturb==1) {std::cout<<"\n Perturb... "; CGAL::perturb_mesh_3(c3t3, domain,sliver_bound=10, time_limit=p.time_lim);}
  if (p.if_lloyd==1)  {std::cout<<"\n Lloyd... ";CGAL::lloyd_optimize_mesh_3(c3t3, domain, time_limit=p.time_lim);}
  if (p.if_odt==1)  {std::cout<<"\n ODT... "; CGAL::odt_optimize_mesh_3(c3t3, domain, time_limit=p.time_lim);}
  if (p.if_exude==1)  {std::cout<<"\n Exude... "; CGAL::exude_mesh_3(c3t3, sliver_bound=10, time_limit=p.time_lim);}
 
  // Output, you can use CGAL text format for that
  /*std::cout<<"\n Saving the mesh... ";
  std::ofstream medit_file("out.mesh");
  c3t3.output_to_medit(medit_file);
  medit_file.close();*/

  //matlab output
  std::cout<<"\n Saving the mesh into matlab file... ";
  int save=save_matlab(c3t3);
  
  std::cout<<"\n ALL DONE, press any key! :)";
  getchar();

  return 0;
}