Ejemplo n.º 1
0
//Function (slot) to read vtk image data
void Application::openvtkclicked()
{
	QString temp = QFileDialog::getOpenFileName(this, tr("Open VTK Data File"),"",tr("VTK Data (*.vtk)"));
	QFile data(temp);
	QString line;
	QTextStream in(&data);
	in.setCodec("UTF-8");
	if (data.open(QFile::ReadOnly)) 
	{
		line = in.readLine();
		if(line.contains("vtk") == true)
		{
			do 
			{
				line = in.readLine();
				if(line.contains("DATASET") == true)
				{
					//call for slicers
					if(line.contains("STRUCTURED_POINTS") == true)//if dataset is compatible
					{
						dataset = line;
						currentfile = temp;
						viewstructuredpointslices();		//calls this function to display slices along axes
						showisotog();						//generates isosurface in case, isosurfacing is true
						Enableall();
					}
					else
					{
						setStatusTip("Unsupported or Invalid Dataset!!");
						QErrorMessage errmsg;
						errmsg.showMessage(tr("Unsupported or Invalid Dataset!!"));
						errmsg.setWindowIcon(QIcon(":/ICONS/Head.jpg"));
						errmsg.exec();
					}
					break;
				}
			} while (!line.isNull());
		}
		else
		{
			this->setStatusTip("Invalid VTK file or file corrupt!!");
			QErrorMessage errmsg;
			errmsg.showMessage(tr("Invalid VTK file or file corrupt!!"));
			errmsg.setWindowIcon(QIcon(":/ICONS/Head.jpg"));
			errmsg.exec();
		}
		data.close();
	}
	else
		this->setStatusTip("File Opening Failed!!");
}
Ejemplo n.º 2
0
//this slot takes the two points as input, for defining a new axis 
//for slicing, the new axis being the line joining these two points.
//This axis is considered as z-axis, whose direction cosines are easily obtained 
//by using simple maths formula. Now, for for other two axis, idea is that they must 
//lie on the plane perpendicular to the axis. So by defining this plane, an arbitrary axis is 
//chosen from this plane as x-axis and direction cosines for y-axis is obtained by using
//cross product rule. For arbitrarily chosing x-axis, concept used is that it must cut atleast 
//one of three coordinate planes.
void Application::defineptr()
{
	double x1=0,y1=0,z1=0,x2=0,y2=0,z2=0,tx,ty,tz;
	double lx,ly,lz,mx,my,mz,nx,ny,nz;	
	bool ok=0;
	CoInputDialog *dialog = new CoInputDialog(&x1,&y1,&z1,&x2,&y2,&z2,&ok);	//taking input of coordinates
	dialog->setStyle(QStyleFactory::create("Plastique"));
	dialog->exec();

	if(!ok)
	{
		return;
	}

	if(x1 == x2 && y1 == y2 && z1 == z2)
	{
		QErrorMessage errmsg;
		errmsg.showMessage(tr("Invalid Input!!"));
		errmsg.setWindowIcon(QIcon(":/ICONS/Head.jpg"));
		errmsg.exec();
		return;
	}

	lz = (x2-x1)/sqrt(pow(x2-x1,2)+pow(y2-y1,2)+pow(z2-z1,2));	//direction cosines of new z-axis
	mz = (y2-y1)/sqrt(pow(x2-x1,2)+pow(y2-y1,2)+pow(z2-z1,2));
	nz = (z2-z1)/sqrt(pow(x2-x1,2)+pow(y2-y1,2)+pow(z2-z1,2));

	if(lz!=0 )							//choosing a coordinate on perpendicular plane
	{
	  tz = 0;
	  ty = 1/sqrt(1+((mz*mz)/(lz*lz)));
	  tx = sqrt(1-(ty*ty));
	}
	else if (mz!=0)
	{
	  tx = 0;
	  tz = 1/sqrt(1+((nz*nz)/(mz*mz)));
	  ty = sqrt(1-(tz*tz));
	}
	else if (nz!=0)
	{
	  ty = 0;
	  tx = 1/sqrt(1+((lz*lz)/(nz*nz)));
	  tz = sqrt(1-(tx*tx));
	}

	lx = tx/sqrt((tx*tx)+(ty*ty)+(tz*tz));		//direction cosines of new x-axis, based on the point choosen
	mx = ty/sqrt((tx*tx)+(ty*ty)+(tz*tz));
	nx = tz/sqrt((tx*tx)+(ty*ty)+(tz*tz));

	ly = (mz*nx) - (mx*nz);		//using cross product, direction cosines of new y-axis
	my = (lx*nz) - (lz*nx);
	ny = (lz*mx) - (lx*mz);

	double arbaxisElements[16] = {			//matrix for reslicing
           lx, mx, nx, 0,
           ly, my, ny, 0,
           lz, mz, nz, 0,
            0,  0,  0, 1 };

	pathmat = vtkMatrix4x4::New();
	pathmat->DeepCopy(arbaxisElements);

	pathmat->SetElement(0, 3, center[0]);
	pathmat->SetElement(1, 3, center[1]);
	pathmat->SetElement(2, 3, center[2]);

	vtkImageReslice *reslice = vtkImageReslice::New();		//setting the new axis
	reslice->SetInputConnection(reader->GetOutputPort());
	reslice->SetOutputDimensionality(2);
	reslice->SetResliceAxes(pathmat);
	reslice->SetInterpolationModeToLinear();

	vtkImageActor *actorx = vtkImageActor::New();
	actorx->SetInput(reslice->GetOutput());
	vtkRenderer *rendererx = vtkRenderer::New();
	rendererx->AddActor(actorx);

	vtkRenderWindow *windx = vtkRenderWindow::New();
	windx->AddRenderer(rendererx);
	
	vtkInteractorStyleImage *imageStyle = vtkInteractorStyleImage::New();
	vtkRenderWindowInteractor *interactor = vtkRenderWindowInteractor::New();
	interactor->SetInteractorStyle(imageStyle);			//setting up interactor style to image style
	windx->SetInteractor(interactor);

	ArbAxisInterCall *Intercall = new ArbAxisInterCall();
	Intercall->SetImageReslice(reslice);
	Intercall->SetInteractor(interactor);

	imageStyle->AddObserver(vtkCommand::MouseMoveEvent, Intercall);		//Adding observer for renedring based on mouse activies
	imageStyle->AddObserver(vtkCommand::LeftButtonPressEvent, Intercall);
    imageStyle->AddObserver(vtkCommand::LeftButtonReleaseEvent, Intercall);

	defaxwid->SetRenderWindow(windx);
	defaxwid->GetRenderWindow()->Render();		//rendering
}