Пример #1
0
Ogre::Real CombatCamera::ZoomResult(Ogre::Real total_move) const
{
    Ogre::Sphere bounding_sphere(Ogre::Vector3(), 0.0);
    if (m_look_at_scene_node)
        bounding_sphere = m_look_at_scene_node->getAttachedObject(0)->getWorldBoundingSphere();
    const Ogre::Real EFFECTIVE_MIN_DISTANCE =
        std::max(bounding_sphere.getRadius() * Ogre::Real(1.05), MIN_ZOOM_IN_DISTANCE);

    Ogre::Real distance_to_look_at_point = DistanceToLookAtPoint();
    if (distance_to_look_at_point + total_move < EFFECTIVE_MIN_DISTANCE)
        total_move += EFFECTIVE_MIN_DISTANCE - (distance_to_look_at_point + total_move);
    else if (MAX_ZOOM_OUT_DISTANCE < distance_to_look_at_point + total_move)
        total_move -= (distance_to_look_at_point + total_move) - MAX_ZOOM_OUT_DISTANCE;
    return distance_to_look_at_point + total_move;
}
Пример #2
0
int main(int argc, char** argv) {
  QApplication app(argc, argv);

  Tr tr;            // 3D-Delaunay triangulation
  C2t3 c2t3 (tr);   // 2D-complex in 3D-Delaunay triangulation

  // the 'function' is a 3D gray level image
  Gray_level_image image("../../../examples/Surface_mesher/data/skull_2.9.inr", 2.9);

  // Carefully choosen bounding sphere: the center must be inside the
  // surface defined by 'image' and the radius must be high enough so that
  // the sphere actually bounds the whole image.
  GT::Point_3 bounding_sphere_center(122., 102., 117.);
  GT::FT bounding_sphere_squared_radius = 200.*200.*2.;
  GT::Sphere_3 bounding_sphere(bounding_sphere_center,
                                   bounding_sphere_squared_radius);

  // definition of the surface, with 10^-2 as relative precision
  Surface_3 surface(image, bounding_sphere, 1e-5);

  // defining meshing criteria
  CGAL::Surface_mesh_default_criteria_3<Tr> criteria(30.,
                                                     5.,
                                                     1.);

  // meshing surface, with the "manifold without boundary" algorithm
  CGAL::make_surface_mesh(c2t3, surface, criteria, CGAL::Manifold_tag());

  QVTKWidget widget;
  widget.resize(256,256);

//   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->SetInput(vtk_image);
//     skinExtractor->SetValue(0, isovalue);
//     skinExtractor->SetComputeNormals(0);
  vtkPolyDataNormals *skinNormals = vtkPolyDataNormals::New();
//     skinNormals->SetInputConnection(skinExtractor->GetOutputPort());
  vtkPolyData* polydata = CGAL::output_c2t3_to_vtk_polydata(c2t3);
  skinNormals->SetInput(polydata);
    skinNormals->SetFeatureAngle(60.0);
  vtkPolyDataMapper *skinMapper = vtkPolyDataMapper::New();
//     skinMapper->SetInputConnection(skinExtractor->GetOutputPort());
  skinMapper->SetInput(polydata);
    skinMapper->ScalarVisibilityOff();
  vtkActor *skin = vtkActor::New();
    skin->SetMapper(skinMapper);

  // An outline provides context around the data.
  //
//   vtkOutlineFilter *outlineData = vtkOutlineFilter::New();
//     outlineData->SetInput(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();
  polydata->Delete();

  widget.show();

  app.exec();
  
  return 0;
}
Пример #3
0
void Volume::display_surface_mesher_result()
{
  if(m_surface.empty() || // Either the surface is not computed.
     m_view_surface) // Or it is computed and displayed, and one want
                     // to recompute it.
  {
    QTime total_time;
    total_time.start();

    values_list->save_values(fileinfo.absoluteFilePath());

    std::size_t nx = m_image.xdim();
    std::size_t ny = m_image.ydim();
    std::size_t nz = m_image.zdim();
    if(nx * ny * nz == 0)
    {
      status_message("No volume loaded.");
      return;
    }

    m_surface.clear();
    sm_timer.reset();
    busy();

    status_message("Surface meshing...");

    sm_timer.start();

    c2t3.clear();
    del.clear();
    Sphere bounding_sphere(m_image.center(),m_image.radius()*m_image.radius());

    Classify_from_isovalue_list classify(values_list);
    Generate_surface_identifiers generate_ids(values_list);

    m_image.set_interpolation(mw->interpolationCheckBox->isChecked());
    if(mw->labellizedRadioButton->isChecked()) {
      std::cerr << "Labellized image\n";
    }
    m_image.set_labellized(mw->labellizedRadioButton->isChecked());
    classify.set_identity(mw->labellizedRadioButton->isChecked());
    generate_ids.set_labellized_image(mw->labellizedRadioButton->isChecked());

    // definition of the surface
    Surface_3 surface(m_image, bounding_sphere, m_relative_precision);
//     Threshold threshold(m_image.isovalue());

    // surface mesh traits class
    typedef CGAL::Surface_mesher::Implicit_surface_oracle_3<Kernel,
      //     typedef CGAL::Surface_mesher::Image_surface_oracle_3<Kernel,
      Surface_3, 
      Classify_from_isovalue_list,
      Generate_surface_identifiers> Oracle;
    Oracle oracle(classify, generate_ids);

    if(mw->searchSeedsCheckBox->isChecked())
    {
      typedef std::vector<std::pair<Point, double> > Seeds;
      Seeds seeds;
      {
	std::cerr << "Search seeds...\n";
	std::set<unsigned char> domains;
	search_for_connected_components(std::back_inserter(seeds),
					CGAL::inserter(domains),
					classify);
	std::cerr << "Found " << seeds.size() << " seed(s).\n";

	if(mw->labellizedRadioButton->isChecked() && 
	   values_list->numberOfValues() == 0) 
	{
	  Q_FOREACH(unsigned char label, domains) {
	    if(label != 0) {
	      values_list->addValue(label);
	    }
	  }
	}
      }
      std::ofstream seeds_out("seeds.off");
      std::ofstream segments_out("segments.txt");
      seeds_out.precision(18);
      seeds_out << "OFF\n" << seeds.size() << " 0 0\n";
      segments_out.precision(18);
      for(Seeds::const_iterator it = seeds.begin(), end = seeds.end();
	  it != end; ++it)
      {
        seeds_out << it->first << std::endl;
	CGAL::Random_points_on_sphere_3<Point> random_points_on_sphere_3(it->second);
	Oracle::Intersect_3 intersect = oracle.intersect_3_object();
	for(int i = 0; i < 20; ++i)
	{
	  const Point test = it->first + (*random_points_on_sphere_3++ - CGAL::ORIGIN);
	  CGAL::Object o = intersect(surface, Segment_3(it->first, test));
	  if (const Point* intersection = CGAL::object_cast<Point>(&o)) {
            segments_out << "2 " << it->first << " " << *intersection << std::endl;
	    del.insert(*intersection);
          }
	  else 
	  {
	    std::cerr << 
	      boost::format("Error. Segment (%1%, %2%) does not intersect the surface! values=(%3%, %4%)\n")
	      % it->first % test
	      % surface(it->first) % surface(test);
	  }
	}
      }
    }
Пример #4
0
int
main(int argc, char* argv[])
{
    // Process command line arguments
    CLI cli(argc, argv);

    // Load image
    std::cout << "Load image." << std::endl;
    const TIFF_image_reader_2 reader(cli.input);
    if (reader.bpp() != 16)
    {
        std::cerr << "Non 16 bit images are not supported.\n";
        return EXIT_FAILURE;
    }

    const Image* const image = reader.get_image<short, K::FT>();

    const LandscapeImage landscape(*image, cli.bottom, cli.z_scale);

    //
    // Surface
    //
    std::cout << "Create mesh surface." << std::endl;
    // Find bounding sphere.
    const K::FT image_center_value =
        *image->interpolate(image->x_size() / 2., image->y_size() / 2.)/cli.z_scale;
    std::cout << "value " << image_center_value << std::endl;

    K::Point_3 bounding_sphere_center(  // Center of the image
        image->x_size() / 2.,
        image->y_size() / 2.,
        (cli.bottom + image_center_value)/2.);
    K::FT bounding_sphere_squared_radius =  // (diagonal/2)^2 = diagonal^2 / 4;
        (POW2(image->x_size()) + POW2(image->y_size()))/4.
            + POW2(std::numeric_limits<short>::max()/cli.z_scale);
    K::Sphere_3 bounding_sphere(bounding_sphere_center,
        bounding_sphere_squared_radius);
    std::cout << "center " << bounding_sphere_center << " r "
        << CGAL::sqrt(bounding_sphere_squared_radius) << std::endl;

    std::cout << "landscape value in center "
        << landscape(bounding_sphere_center) << std::endl;

    Surface surface(landscape, bounding_sphere, 1e-3/CGAL::sqrt(bounding_sphere_squared_radius));

    CGAL::Surface_mesh_default_criteria_3<Tr> mesh_criteria(
        cli.angular_bound,
        cli.facet_size,
        cli.approximation);


    //
    // Mesh generation
    //
    std::cout << "Start mesh generation." << std::endl;
    Tr tr;
    C2t3 c2t3(tr);
    CGAL::make_surface_mesh(c2t3, surface, mesh_criteria, CGAL::Manifold_with_boundary_tag());

    delete image;

    std::ofstream out(cli.output);
    out << std::setprecision(17);
    CGAL::output_surface_facets_to_off(out, c2t3);
    return 0;
}