void VTKImageWidgetImplementation::commonInit()
{
	//  m_OptionWidget = new OptionWidget( this, m_ViewerCore );
	m_Layout->addWidget( this );
	m_Layout->setMargin( 0 );
	setFocus();
	SetRenderWindow( m_RenderWindow );
	setAcceptDrops( true );
	m_RenderWindow->AddRenderer( m_Renderer );
	m_Renderer->SetBackground( 0.1, 0.2, 0.4 );
	m_OpacityGradientFactor = 0;
	m_CameraDistance = 500;
	m_RightButtonPressed = false;
	m_LeftButtonPressed = false;

	if( m_ViewerCore->getSettings()->getPropertyAs<bool>( "showCrosshair" ) ) {
		m_Cursor->AllOn();
		m_Cursor->OutlineOff();
	} else {
		m_Cursor->AllOff();
	}

	m_Cursor->Update();
	m_CursorMapper->SetInputConnection( m_Cursor->GetOutputPort() );
	m_Actor->SetMapper( m_CursorMapper );
	m_Renderer->AddActor( m_Actor );
	m_MapperType = VTKImageComponents::CPU_FixedPointRayCast;
}
Ejemplo n.º 2
0
PointCloudViewer::PointCloudViewer(QWidget* parent, Qt::WindowFlags f): QVTKWidget(parent, f)
{
    mImpl = new PointCloudViewer::Impl;
    mImpl->Vis.addPointCloud(common::KinectPointCloud::Ptr(new common::KinectPointCloud));
    Eigen::Affine3f trans;
    trans.setIdentity();
    trans.rotate(Eigen::AngleAxisf(3.14159265, Eigen::Vector3f(0, 0, 1)));
    
    mImpl->Vis.addCoordinateSystem(1.0, trans);
    mImpl->Vis.setBackgroundColor(0, 0, 0);
    SetRenderWindow(mImpl->Vis.getRenderWindow().GetPointer());
}
Ejemplo n.º 3
0
void main(){
	typedef itk::Image<signed short, 2> imagetype;
	typedef itk::ImageFileReader<imagetype> imagereadertype;
	typedef itk::ImageToVTKImageFilter<imagetype> connerctortypr;

	imagereadertype::Pointer reader = imagereadertype::New();
	reader->SetFileName("e:/IM-0001-0001.dcm");
	auto iotype = itk::GDCMImageIO::New();
	reader->SetImageIO(iotype);

	try{
		reader->Update();
	}
	catch (itk::ExceptionObject e){
		std::cerr << "exception in file reader " << std::endl;
		std::cerr << e.GetDescription() << std::endl;
		std::cerr << e.GetLocation() << std::endl;
	}

	connerctortypr::Pointer connector = connerctortypr::New();
	connector->SetInput(reader->GetOutput());
	connector->Update();

	auto flip = vtkImageFlip::New();
	flip->SetInputData(connector->GetOutput());
	flip->SetFilteredAxis(1);
	flip->Update();

	auto actor = vtkImageActor::New();
	//actor->GetMapper()->SetInputData(flip->GetOutput());
	actor->SetInputData(flip->GetOutput());
	actor->InterpolateOff();
	actor->Update();

	auto render = vtkRenderer::New();
	render->AddActor(actor);

	auto window = vtkRenderWindow::New();
	window->SetSize(800, 600);
	window->AddRenderer(render);
	

	auto interactor = vtkRenderWindowInteractor::New();
	interactor->SetRenderWindow(window);

	interactor->Initialize();
	interactor->Start();
}
Ejemplo n.º 4
0
FieldDataVisualizer::FieldDataVisualizer(QWidget* parent): QVTKOpenGLWidget(parent){
	vtkNew<vtkGenericOpenGLRenderWindow> window;
	SetRenderWindow(window.Get());
	
	// Camera
	vtkSmartPointer<vtkCamera> camera = vtkSmartPointer<vtkCamera>::New();
	camera->SetViewUp(0, 1, 0);
	camera->SetPosition(0, 0, 10);
	camera->SetFocalPoint(0, 0, 0);

	// Renderer
	myRenderer = vtkSmartPointer<vtkRenderer>::New();
	myRenderer->SetActiveCamera(camera);

	// Setup the background gradient
	myRenderer->GradientBackgroundOn();
	myBGColor = QColor(255, 235, 100);
	setBackgroundGradient(myBGColor.red(), myBGColor.green(), myBGColor.blue());
	GetRenderWindow()->AddRenderer(myRenderer);

	//Draw compass
	displayCompass();

	// Some members
	mySelectedMapper = vtkSmartPointer<vtkDataSetMapper>::New();
	mySelectedActor = vtkSmartPointer<vtkActor>::New();
	myScalarBarWidget = vtkSmartPointer<vtkScalarBarWidget>::New();
	selectedPickActor = vtkActor::New();
	//mySelectedProperty = vtkSmartPointer<vtkProperty>::New();
	myEdgeActor = vtkActor::New();
	edgeExtractor = vtkExtractEdges::New();
	edgeMapper = vtkPolyDataMapper::New();
	warpFilter = vtkWarpVector::New();
	hueLut = vtkLookupTable::New();

	//Properties
	isAnimationSceneInstantiated = false;

	myVtkViewer = new VtkViewer(*this);

	setPickerModeNone();
	setViewMode(true);
	myHarmonicScale = 1;


	myVtkAnimatorActive = false;
}
Ejemplo n.º 5
0
ChartWidget::ChartWidget()
{
    // indexing
    index_ = numChartWidgets_;
    numChartWidgets_++;

    // setup the view
    view_ = vtkSmartPointer<vtkContextView>::New();
    view_->GetRenderer()->SetBackground(1.,1.,1.);
    view_->SetInteractor(GetInteractor());
    SetRenderWindow(view_->GetRenderWindow());

    // create chart and add it to view
    chart_ = vtkSmartPointer<vtkChartXY>::New();
    view_->GetScene()->AddItem(chart_);

    // show legend, by default in the lower left
    chart_->SetShowLegend(true);
    chart_->GetLegend()->SetVerticalAlignment(vtkChartLegend::BOTTOM);
    chart_->GetLegend()->SetHorizontalAlignment(vtkChartLegend::LEFT);

    // don't allow zooming out beyond range of data
    chart_->SetForceAxesToBounds(true);

    // right button zooms (instead of selects)
    chart_->SetActionToButton(vtkChart::ZOOM, vtkContextMouseEvent::RIGHT_BUTTON);

    // create SVG exporter
    svgExporter_ = vtkSmartPointer<vtkGL2PSExporter>::New();

    // use an off-screen constant-sized render window for SVG export
    svgRenderWindow_ = vtkSmartPointer<vtkRenderWindow>::New();
    svgRenderWindow_->OffScreenRenderingOn();
    svgRenderWindow_->SetSize(480, 300);

    svgExporter_->SetRenderWindow(svgRenderWindow_);

    svgExporter_->SetFileFormatToSVG();
    svgExporter_->CompressOff();
    svgExporter_->SetSortToOff();
    svgExporter_->TextAsPathOn();

    // set minimum height
    setMinimumHeight(150);
}
Ejemplo n.º 6
0
int main(int, char *[])
{

  const std::string file = "/home/mathieu/dev/cochleo/share/cochlee.wav";
  const audiofile audio(file);
  filterbank fb(audio.sample_frequency(),100,6000,1000);

  const auto xaxis = audio.time();
  const auto yaxis = fb.center_frequency();
  auto cochleo = fb.compute(audio.channel(0));
  normalization(cochleo);

  // Create the color palette  
  auto palette = vtkSmartPointer<vtkLookupTable>::New();
  palette->SetTableRange(0.0,1.0);
  palette->SetHueRange(0.67,0.);
  palette->SetSaturationRange(0.7,0.3);
  palette->Build();
     
  // Create a c-style rgb image
  const std::size_t width = xaxis.size();
  const std::size_t height = yaxis.size();
  std::vector<unsigned char> cImage(3*width*height);
  
  for(std::size_t i=0; i<width; ++i)
    for(std::size_t j=0; j<height; ++j)
      {
  	unsigned char* color = palette->MapValue(cochleo[i][j]);
  	cImage[3*(i+width*j)]   = color[0];
  	cImage[3*(i+width*j)+1] = color[1];
  	cImage[3*(i+width*j)+2] = color[2];
      }
  
  // Convert the c-style image to a vtkImageData
  auto imageImport = vtkSmartPointer<vtkImageImport>::New();
  imageImport->SetDataSpacing(0.07, 1, 1);
  imageImport->SetDataOrigin(0, 0, 0);
  imageImport->SetWholeExtent(0, width-1, 0, height-1, 0, 0);
  imageImport->SetDataExtentToWholeExtent();
  imageImport->SetDataScalarTypeToUnsignedChar();
  imageImport->SetNumberOfScalarComponents(3);
  imageImport->SetImportVoidPointer(cImage.data());
  imageImport->Update();
 
  // Create an actor
  auto actor = vtkSmartPointer<vtkImageActor>::New();
  actor->SetInput(imageImport->GetOutput());
  
  // Create a scalar bar
  auto scalarBar = vtkSmartPointer<vtkScalarBarActor>::New();
  scalarBar->SetLookupTable(palette);
  scalarBar->SetTitle("gain");
  scalarBar->SetNumberOfLabels(5);

  // Configure text of the scalar bar
  auto textBar = vtkSmartPointer<vtkTextProperty>::New();
  textBar->SetFontSize(10);
  scalarBar->SetTitleTextProperty(textBar);
  scalarBar->SetLabelTextProperty(textBar);
   
  // Setup renderer
  auto renderer = vtkSmartPointer<vtkRenderer>::New();
  renderer->AddActor(actor);
  renderer->AddActor(scalarBar);
  renderer->ResetCamera();
  
  // Setup render window
  auto renderWindow = vtkSmartPointer<vtkRenderWindow>::New();
  renderWindow->AddRenderer(renderer);
 
  // Setup render window interactor
  auto renderWindowInteractor = vtkSmartPointer<vtkRenderWindowInteractor>::New();
  auto style = vtkSmartPointer<vtkInteractorStyleImage>::New();
 
  renderWindowInteractor->SetInteractorStyle(style);
 
  // Render and start interaction
  renderWindowInteractor->SetRenderWindow(renderWindow);
  renderWindowInteractor->Initialize();
  renderWindowInteractor->Start();
 
  return EXIT_SUCCESS;
}
Ejemplo n.º 7
0
HRESULT KGraphicsEngine::Toggle2Windowed()
{
	if (m_lpCurScene)
	{
		g_cMeshTable.InvalidateDeviceObjects();
		g_SceneTable.InvalidateDeviceObjects();
	}
	g_EffectMgr.InvalidateDeviceObjects();

	if (m_bUseMotionBlur)
	{
		BackBufferRelease();
	}

	HRESULT hr = S_OK;
	
	GetWindowRect(m_LastRenderWindow,&m_RenderWindowRect);
		
	//m_PresentParam.BackBufferWidth = m_RenderWindowRect.right-m_RenderWindowRect.left ;
    //m_PresentParam.BackBufferHeight= m_RenderWindowRect.bottom - m_RenderWindowRect.top;
	m_PresentParam.BackBufferWidth = m_DisplayMode.Width;
    m_PresentParam.BackBufferHeight= m_DisplayMode.Height;

  	D3DFORMAT  DepFormat;
	if (SUCCEEDED(g_pD3D->CheckDepthStencilMatch(D3DADAPTER_DEFAULT,
		D3DDEVTYPE_HAL,
		m_DisplayMode.Format,
		m_DisplayMode.Format,
		D3DFMT_D24S8)))
	{
		DepFormat = D3DFMT_D24S8;
	}
	else
	{
		DepFormat = D3DFMT_D16;
	}
	m_PresentParam.Windowed = TRUE ;
    m_PresentParam.SwapEffect = D3DSWAPEFFECT_DISCARD;
    m_PresentParam.BackBufferFormat = m_DisplayMode.Format;
	m_PresentParam.EnableAutoDepthStencil = TRUE;
    m_PresentParam.AutoDepthStencilFormat = DepFormat;
    m_PresentParam.MultiSampleType = D3DMULTISAMPLE_NONE;
    m_PresentParam.hDeviceWindow = g_hBaseWnd;
    m_PresentParam.Flags = 0;
    m_PresentParam.FullScreen_RefreshRateInHz = 0;
	m_PresentParam.BackBufferCount = 0;
    m_PresentParam.PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT;

	//just set camera's aspect
	m_cCamera.Aspect = m_PresentParam.BackBufferWidth*1.0f/m_PresentParam.BackBufferHeight; 

	g_pd3dDevice->SetDialogBoxMode( FALSE );
   
	if ( FAILED(hr = g_pd3dDevice->Reset( &m_PresentParam )))
    {
        //fprintf(Note,"Create D3D Device Failed.\n");
		if (hr == D3DERR_INVALIDCALL)
			MessageBox(g_hBaseWnd,"Toggle to Windowed Failed!","Failed in Toggling",0);
		else if (hr == E_OUTOFMEMORY )
			MessageBox(g_hBaseWnd,"Direct3D could not allocate sufficient memory to complete the call.","Failed Create Device!",0);
		else if (hr == D3DERR_OUTOFVIDEOMEMORY)
			MessageBox(g_hBaseWnd,"Direct3D does not have enough display memory to perform the operation. ","Failed Create Device!",0);

        return E_FAIL;
    }
	SetWindowLong( g_hBaseWnd , GWL_STYLE, m_BaseWinStyle );

	SetRenderWindow(m_LastRenderWindow);

	m_bWindowed = TRUE;

	if (m_lpCurScene)
	{
		g_cMeshTable.RestoreDeviceObjects();
		g_SceneTable.RestoreDeviceObjects();
	}
	g_EffectMgr.RestoreDeviceObjects();

	if (m_bUseMotionBlur)
	{
		BackBufferCreate();
	}
	return S_OK;
}