GsTLPoint Structured_grid_coord_mapper::uvw_coords(GsTLPoint xyz)  {
  vtkSmartPointer<vtkStructuredGrid> geom = sgrid_->get_structured_geometry();


  // Need to get the ijk of the cell and add the parametric coordinate once normalized

  vtkSmartPointer<vtkGenericCell> gcell = vtkSmartPointer<vtkGenericCell>::New();
  
  double xyzcoord[3];
  xyzcoord[0] = xyz.x();
  xyzcoord[1] = xyz.y();
  xyzcoord[2] = xyz.z();

  double pcoord[3];
  double weights[8];
  int subid;

  int cellid = geom->FindCell(xyzcoord,0,gcell,-1,1e-4,subid,pcoord,weights);

  //If it outside the grid, ensure that it is so far away that it will get pickup within a neighborhood
  if(cellid <0 ) return GsTLPoint(xyzcoord[0] + 9e9,xyzcoord[1] + 9e9,xyzcoord[2] + 9e9);
  //geom->GetCell(cellid, gcell);  //may not be necessary if gcell is already stored in the FindCell
  int i,j,k;
  sgrid_->cursor()->coords(cellid,i,j,k);

  //Th u,v,w coordinates ranges from 0-1

  double u = (static_cast<double>(i) + pcoord[0])/grid_cell_number_.x();
  double v = (static_cast<double>(j) + pcoord[1])/grid_cell_number_.y();
  double w = (static_cast<double>(k) + pcoord[2])/grid_cell_number_.z();

  return GsTLPoint(u,v,w );

}
Beispiel #2
0
int Oinv_cgrid::add_slice( Oinv::Axis axis, int position,
                           bool showed ) {

    GsTLCoordVector cell_dims = grid_->cell_dimensions();

    // notice that the origin returned by the grid is the center
    // of the origin cell, not its corner (cell-centered grid)
    GsTLPoint origin = grid_->origin();

    GsTLVector<int> grid_sizes( grid_->nx(), grid_->ny(), grid_->nz() );
    int max_pos = grid_sizes[axis]-1;

    Oinv_slice_cgrid* new_slice =
        new Oinv_slice_cgrid( axis, position, grid_sizes,
                              voxel_data_, &initialized_, cmap_,
                              cell_dims[0], cell_dims[1], cell_dims[2],
                              origin.x(), origin.y(), origin.z() );

    new_slice->property_display_mode( property_display_mode_ );
    GsTL_SoNode* node = new_slice->oinv_node();
    node->visible = showed;
    //new_slice->oinv_node()->visible = showed;

    slices_.push_back( new_slice );
    slices_node_->addChild( new_slice->oinv_node() );

    return slices_.size()-1;
}
Beispiel #3
0
void Qt_cartesian_grid_summary::init( const Geostat_grid* grid ) {
  //TL modified
  const Cartesian_grid* cgrid = dynamic_cast<const Cartesian_grid*>( grid );
  if( !cgrid ) return;

  geostat_grid_ = cgrid;
  GsTLCoordVector cell_dims = cgrid->cell_dimensions();
  GsTLPoint origin = cgrid->origin();

  desc_widget_ = new QGroupBox( 1, Qt::Horizontal );
  QGroupBox* groupbox = (QGroupBox*) desc_widget_;
  groupbox->setInsideSpacing( 4 );

  QString count;
  QFont font;
  font.setBold(true);

  // number of cells
  QLabel* dimslabel;
  dimslabel = new QLabel( "Number of cells", groupbox );
  dimslabel->setFont( font );
  count.setNum( cgrid->nx() );
  new QLabel( QString("X: ")+count, groupbox );
  count.setNum( cgrid->ny() );
  new QLabel( QString("Y: ")+count, groupbox );
  count.setNum( cgrid->nz() );
  new QLabel( QString("Z: ")+count, groupbox );

  QLabel * num;
  

  // cell dimensions
  groupbox->addSpace( 8 );
  QLabel* sizelabel = new QLabel( "Cells dimensions", groupbox );
  sizelabel->setFont( font );
  count.setNum( cell_dims.x() );
  new QLabel( QString("X: ")+count, groupbox );
  count.setNum( cell_dims.y() );
  new QLabel( QString("Y: ")+count, groupbox );
  count.setNum( cell_dims.z() );
  new QLabel( QString("Z: ")+count, groupbox );

  // Origin
  groupbox->addSpace( 8 );
  QLabel* originlabel = new QLabel( "Origin (center of origin cell)", groupbox );
  originlabel->setFont( font );
  count.setNum( origin.x() );
  new QLabel( QString("X: ")+count, groupbox );
  count.setNum( origin.y() );
  new QLabel( QString("Y: ")+count, groupbox );
  count.setNum( origin.z() );
  new QLabel( QString("Z: ")+count, groupbox );

}; 
 void vtkProp_cgrid::init( Geostat_grid* grid, vtkRenderer* renderer ) {
	 renderer_ = renderer;
    geostat_grid_ = grid;
    grid_ = dynamic_cast<Cartesian_grid*>( grid );
  GsTLCoordVector cell_dims = grid_->cell_dimensions();
  GsTLPoint origin = grid_->origin();

  // Need to double check the origin to be sure it fits the center of the cell

  image_data_ = vtkUniformGrid::New();
  image_data_->SetExtent(0,grid_->nx(), 0,grid_->ny(), 0,grid_->nz());
  image_data_->SetOrigin(origin.x()-cell_dims.x()/2, origin.y()-cell_dims.y()/2,origin.z()-cell_dims.z()/2);
  image_data_->SetSpacing(cell_dims.x(),cell_dims.y(),cell_dims.z());
//  image_data_->SetScalarTypeToFloat ();
  image_data_->GetCellData()->SetScalars(0);
  image_data_->GetPointData()->SetScalars(0);

// Set the thresholder for the region; perform the thresholding based on the visibility array
  region_threshold_ = vtkThreshold::New();
  region_threshold_->SetInputData(image_data_);
  region_threshold_->SetInputArrayToProcess(0,0,0,vtkDataObject::FIELD_ASSOCIATION_CELLS,vtkDataSetAttributes::SCALARS);
  region_threshold_->ThresholdBetween(-1e9,1e9);

  data_pass_through_filter_ = vtkPassThrough::New();
  data_pass_through_filter_->SetInputData(image_data_);

  surface_extractor_ = vtkDataSetSurfaceFilter::New();
  surface_extractor_->SetInputArrayToProcess(0,0,0,vtkDataObject::FIELD_ASSOCIATION_CELLS,vtkDataSetAttributes::SCALARS);
  //surface_extractor_->SetInput((vtkDataSet*)data_pass_through_filter_->GetOutput());
  surface_extractor_->SetInputConnection(data_pass_through_filter_->GetOutputPort());

	vtk_property_->SetRepresentationToSurface();
	vtk_property_->EdgeVisibilityOff();

  mapper_ = vtkDataSetMapper::New();
  mapper_->SetInputConnection(surface_extractor_->GetOutputPort());

  actor_ = vtkActor::New();
  actor_->SetProperty(vtk_property_);
  actor_->SetMapper(mapper_);
  actor_->PickableOn();
  actor_->RotateZ(-1.0*grid_->geometry()->rotation_z());

  this->set_visibility(false);
  renderer_->AddActor(actor_);

  //build a cutter for testing
  
}
QDomElement Structured_grid_geometry_xml_io::
  write_grid_geometry( QDir dir, QDomDocument& dom, const  Geostat_grid* grid) const{

	const Reduced_grid *mgrid =  dynamic_cast<const Reduced_grid*>( grid );

	const Structured_grid* struct_grid = dynamic_cast<const Structured_grid*>(grid);

	 QDomElement elemGeom = dom.createElement("Geometry");
	 elemGeom.setAttribute("nx",struct_grid->nx());
	 elemGeom.setAttribute("ny",struct_grid->ny());
	 elemGeom.setAttribute("nz",struct_grid->nz());
   elemGeom.setAttribute("rotation_z_angle",struct_grid->rotation_z());

  QFile file( dir.absoluteFilePath("corner_coordinates.sgems" ) );
  if( !file.open( QIODevice::WriteOnly ) ) {
  	elemGeom.clear();
  	return elemGeom;
  }
	QDataStream stream( &file );
  /*
	#if QT_VERSION >= 0x040600
		stream.setFloatingPointPrecision(QDataStream::SinglePrecision);
	#endif
  */
  stream.setFloatingPointPrecision(QDataStream::DoublePrecision);

  int n_points = (struct_grid->nx()+1)*(struct_grid->ny()+1)*(struct_grid->nz()+1);

	for(int i=0; i<n_points; ++i) {
    GsTLPoint pt = struct_grid->get_corner_point_locations(i);
    stream<< pt.x();
    stream<< pt.y();
    stream<< pt.z();
  }
	file.close();
	return elemGeom;

}
GsTLPoint Structured_grid_coord_mapper::xyz_coords(GsTLPoint uvw)  {
  vtkSmartPointer<vtkStructuredGrid> geom = sgrid_->get_structured_geometry();

  int i,j,k;
  int node_id = sgrid_->closest_node(uvw);
  sgrid_->cursor()->coords(node_id,i,j,k);

  //The coordinates wihtin the cell
  double pcoords[3];
  pcoords[0] = uvw.x() - static_cast<double>(i)/grid_cell_number_.x();
  pcoords[1] = uvw.y() - static_cast<double>(j)/grid_cell_number_.y();
  pcoords[2] = uvw.z() - static_cast<double>(k)/grid_cell_number_.z();

  double xyz[3];
  double* weights;
  vtkSmartPointer<vtkGenericCell> cell = vtkSmartPointer<vtkGenericCell>::New();
  geom->GetCell(node_id,cell);
  int subid=0;
  cell->EvaluateLocation(subid,pcoords,xyz,weights);
  return GsTLPoint(xyz[0],xyz[1],xyz[2]);


}
void Log_data::add_segment_geometry(Log_data::Segment_geometry& segment_geom){
  std::map<int, Segment_geometry>::const_iterator it = log_geometry_.find(segment_geom.nodeid);
	if(it == log_geometry_.end()) {
    log_geometry_[segment_geom.nodeid] = segment_geom;
//    log_coords_[segment_geom.nodeid] = std::make_pair(segment_geom.start,segment_geom.end);
		GsTLPoint d = segment_geom.start-segment_geom.end;
		double length = sqrt(d.x()*d.x() + d.y()*d.y() + d.z()*d.z());
		if( length < min_segment_length_ ) min_segment_length_ = length;
		if( length > max_segment_length_ ) max_segment_length_ = length;
	//	lengths_[segment_geom.nodeid] = length;
    total_length_ +=  length;
 //   from_to_[segment_geom.nodeid] = std::make_pair(segment_geom.from,segment_geom.to);
	}
}
Beispiel #8
0
bool GsTL_cube::contains( const GsTLPoint& P ) const {
  if( P.x() < lower_.x() ) return false;
  if( P.y() < lower_.y() ) return false;
  if( P.z() < lower_.z() ) return false;
  
  if( P.x() > upper_.x() ) return false;
  if( P.y() > upper_.y() ) return false;
  if( P.z() > upper_.z() ) return false;

  return true;
}
Beispiel #9
0
void Qt_masked_grid_summary::init( const Geostat_grid* grid ) {
  //TL modified
  const Reduced_grid * rgrid = dynamic_cast<const Reduced_grid*>(grid);
  if( !rgrid ) return;

  //geostat_grid_ = cgrid;
  GsTLCoordVector cell_dims = rgrid->cell_dimensions();
  GsTLPoint origin = rgrid->origin();

  desc_widget_ = new QGroupBox( 1, Qt::Horizontal );
  QGroupBox* groupbox = (QGroupBox*) desc_widget_;
  groupbox->setInsideSpacing( 4 );

  QString count;
  QFont font;
  font.setBold(true);


  QLabel * title;
  title = new QLabel(QString("Grid with inactive cells"),groupbox);
  title->setFont(font);


  // number of cells
  QLabel* dimslabel;
  dimslabel = new QLabel ("Bounding box", groupbox);
  dimslabel->setFont( font );
  count.setNum( rgrid->nx() );
  new QLabel( QString("X: ")+count, groupbox );
  count.setNum( rgrid->ny() );
  new QLabel( QString("Y: ")+count, groupbox );
  count.setNum( rgrid->nz() );
  new QLabel( QString("Z: ")+count, groupbox );

  //TL modified
  QLabel * num;
  num = new QLabel(QString("# of active cells: ")+count.setNum(rgrid->numActive()), groupbox);
  num->setFont(font);


  // cell dimensions
  groupbox->addSpace( 8 );
  QLabel* sizelabel = new QLabel( "Cells dimensions", groupbox );
  sizelabel->setFont( font );
  count.setNum( cell_dims.x() );
  new QLabel( QString("X: ")+count, groupbox );
  count.setNum( cell_dims.y() );
  new QLabel( QString("Y: ")+count, groupbox );
  count.setNum( cell_dims.z() );
  new QLabel( QString("Z: ")+count, groupbox );

  // Origin
  groupbox->addSpace( 8 );
  QLabel* originlabel = new QLabel( "Origin (center of origin cell)", groupbox );
  originlabel->setFont( font );
  count.setNum( origin.x() );
  new QLabel( QString("X: ")+count, groupbox );
  count.setNum( origin.y() );
  new QLabel( QString("Y: ")+count, groupbox );
  count.setNum( origin.z() );
  new QLabel( QString("Z: ")+count, groupbox );

}
Beispiel #10
0
void Oinv_cgrid::init( const Geostat_grid* grid ) {
    geostat_grid_ = grid;
    grid_ = dynamic_cast<const Cartesian_grid*>( grid );

    SbVec3s dim = SbVec3s( grid_->nx(), grid_->ny(), grid_->nz() );

    voxel_data_ = new uint8_t[ grid_->size() ];
    initialized_ = false;


    painted_switch_ = new SoSwitch;
    oinv_node_->addChild( painted_switch_ );

    // display the bounding box if no property is painted
    GsTLCoordVector cell_dims = grid_->cell_dimensions();
    GsTLPoint origin = grid_->origin();

    OinvBBox* bbox =
        new OinvBBox( origin.x()-cell_dims.x()/2, origin.y()-cell_dims.y()/2,
                      origin.z()-cell_dims.z()/2,
                      float(grid_->nx())*cell_dims.x(),
                      float(grid_->ny())*cell_dims.y(),
                      float(grid_->nz())*cell_dims.z() );
    painted_switch_->addChild( bbox->oinv_node() );



    /* When a property is painted, we can show:
     * 1- the bounding box
     * 2- the outer planes of the volume ("full volume")
     * 3- volume rendering
     * 4- slices
     * Options (2) and (3) are mutually exclusive.
     * All these options are contained inside the same separator,
     * called 'painted_main_separator'
    */
    SoSeparator* painted_main_separator = new SoSeparator;
    painted_switch_->addChild( painted_main_separator );


    //-------------------------
    // bounding box node
    bbox_switch_ = new GsTL_SoNode;
    painted_main_separator->addChild( bbox_switch_ );
    bbox_switch_->addChild( bbox->oinv_node() );
    bbox_switch_->visible = false;


    display_switch_ = new SoSwitch;
    painted_main_separator->addChild( display_switch_ );


    //-------------------------
    // Volume rendering node

    SoSeparator * vol_rendering_and_slices_root = new SoSeparator;
    display_switch_->addChild( vol_rendering_and_slices_root );

    SoSeparator * vol_rendering_root = new SoSeparator;
    vol_rendering_and_slices_root->addChild( vol_rendering_root );

    clipplane_switch_ = new SoSwitch;
    vol_rendering_root->addChild( clipplane_switch_ );
    setup_clipplanes();

    /*
    SbBox3f vol_size( origin.x(), origin.y(), origin.z(),
                      origin.x()+float(grid_->nx())*cell_dims.x(),
                      origin.y()+float(grid_->ny())*cell_dims.y(),
                      origin.z()+float(grid_->nz())*cell_dims.z() );
    */
    SbBox3f vol_size( origin.x()-cell_dims.x()/2,
                      origin.y()-cell_dims.y()/2,
                      origin.z()-cell_dims.z()/2,
                      origin.x()-cell_dims.x()/2+float(grid_->nx())*cell_dims.x(),
                      origin.y()-cell_dims.y()/2+float(grid_->ny())*cell_dims.y(),
                      origin.z()-cell_dims.z()/2+float(grid_->nz())*cell_dims.z() );

    // Add SoVolumeData to scene graph
    volume_data_ = new SoVolumeData();
    volume_data_->setVolumeData(dim, voxel_data_, SoVolumeData::UNSIGNED_BYTE);
    volume_data_->setVolumeSize( vol_size );
    vol_rendering_root->addChild(volume_data_);

    // Add TransferFunction (color map) to scene graph
    volrend_colormap_ = new SoTransferFunction();
    volrend_colormap_->predefColorMap.setValue(SoTransferFunction::NONE);
    volrend_colormap_->colorMapType.setValue(SoTransferFunction::RGBA);
    vol_rendering_root->addChild( volrend_colormap_ );

    // Add VolumeRender to scene graph
    rendering_switch_ = new SoSwitch;
    SoVolumeRender * volrend = new SoVolumeRender();
    volrend->interpolation = SoVolumeRender::NEAREST;
    if( requires_manual_override( float(grid_->nx())*cell_dims.x(),
                                  float(grid_->ny())*cell_dims.y(),
                                  float(grid_->nz())*cell_dims.z() ) ) {
        volrend->numSlicesControl.setValue(SoVolumeRender::MANUAL);
        int num_slices = int( float(grid_->nx())*cell_dims.x() );
        num_slices += int( float(grid_->ny())*cell_dims.y() );
        num_slices += int( float(grid_->nz())*cell_dims.z() );
        volrend->numSlices.setValue(num_slices);
    }

    rendering_switch_->addChild(volrend);
    rendering_switch_->whichChild = 0;

    vol_rendering_root->addChild(rendering_switch_);


    //-------------------------
    // Slices

    SoSeparator * slices_root = new SoSeparator;
    vol_rendering_and_slices_root->addChild( slices_root );

    slices_node_ = new SoGroup;
    slices_root->addChild( slices_node_ );



    //-------------------------
    // Full volume node

    SoSeparator * full_vol_root = new SoSeparator;
    display_switch_->addChild( full_vol_root );

    full_volume_ =
        new Full_volume( grid_->nx(), grid_->ny(), grid_->nz(),
                         voxel_data_, &initialized_, cmap_,
                         cell_dims.x(), cell_dims.y(), cell_dims.z(),
                         origin.x(), origin.y(), origin.z() );

    full_vol_root->addChild( full_volume_->oinv_node() );

    //-------------------------
    display_switch_->whichChild = 1;
    //painted_switch_->whichChild = 0;


    property_display_mode( Oinv::NOT_PAINTED );

}