Exemplo n.º 1
0
void EraserWidget::eraseVolume(TYPE* volumePointer)
{
	ImagePtr image = mPatientModelService->getActiveImage();
	vtkImageDataPtr img = image->getBaseVtkImageData();


	Eigen::Array3i dim(img->GetDimensions());
	Vector3D spacing(img->GetSpacing());

	Transform3D rMd = mVisualizationService->getGroup(0)->getOptions().mPickerGlyph->get_rMd();
	Vector3D c(mSphere->GetCenter());
	c = rMd.coord(c);
	double r = mSphere->GetRadius();
	mPreviousCenter = c;
	mPreviousRadius = r;

	DoubleBoundingBox3D bb_r(c[0]-r, c[0]+r, c[1]-r, c[1]+r, c[2]-r, c[2]+r);

	Transform3D dMr = image->get_rMd().inv();
	Transform3D rawMd = createTransformScale(spacing).inv();
	Transform3D rawMr = rawMd * dMr;
	Vector3D c_d = dMr.coord(c);
	double r_d = dMr.vector(r * Vector3D::UnitX()).length();
	c = rawMr.coord(c);
	r = rawMr.vector(r * Vector3D::UnitX()).length();
	DoubleBoundingBox3D bb0_raw = transform(rawMr, bb_r);
	IntBoundingBox3D bb1_raw(0, dim[0], 0, dim[1], 0, dim[2]);

//	std::cout << "     sphere: " << bb0_raw << std::endl;
//	std::cout << "        raw: " << bb1_raw << std::endl;

	for (int i=0; i<3; ++i)
	{
		bb1_raw[2*i] = std::max<double>(bb1_raw[2*i], bb0_raw[2*i]);
		bb1_raw[2*i+1] = std::min<double>(bb1_raw[2*i+1], bb0_raw[2*i+1]);
	}

	int replaceVal = mEraseValueAdapter->getValue();

	for (int x = bb1_raw[0]; x < bb1_raw[1]; ++x)
		for (int y = bb1_raw[2]; y < bb1_raw[3]; ++y)
			for (int z = bb1_raw[4]; z < bb1_raw[5]; ++z)
			{
				int index = x + y * dim[0] + z * dim[0] * dim[1];
				if ((Vector3D(x*spacing[0], y*spacing[1], z*spacing[2]) - c_d).length() < r_d)
					volumePointer[index] = replaceVal;
			}
}
Exemplo n.º 2
0
void CustomMetric::updateTexture(MeshPtr model, Transform3D rMrr)
{
	if (!model)
		return;

	if (!this->getTextureFollowTool() || !model->hasTexture())
		return;

	// special case:
	// Project tool position down to the model, then set that position as
	// the texture x pos.

	Transform3D rMt = mSpaceProvider->getActiveToolTipTransform(CoordinateSystem::reference());
	Transform3D rMd = rMrr * model->get_rMd();
	Vector3D t_r = rMt.coord(Vector3D::Zero());
	Vector3D td_r = rMt.vector(Vector3D::UnitZ());

	DoubleBoundingBox3D bb_d = model->boundingBox();
	Vector3D bl = bb_d.bottomLeft();
	Vector3D tr = bb_d.topRight();
	Vector3D c = (bl+tr)/2;
	Vector3D x_min_r(c[0], bl[1], c[2]);
	Vector3D x_max_r(c[0], tr[1], c[2]);
	x_min_r = rMd.coord(x_min_r);
	x_max_r = rMd.coord(x_max_r);

	double t_x = dot(t_r, td_r);
	double bbmin_x = dot(x_min_r, td_r);
	double bbmax_x = dot(x_max_r, td_r);
	double range = bbmax_x-bbmin_x;
	if (similar(range, 0.0))
		range = 1.0E-6;
	double s = (t_x-bbmin_x)/range;
	model->getTextureData().getPositionY()->setValue(s);
}
Transform3D ToolTipCalibrationCalculator::get_sMt_new()
{
  Transform3D sMt_old = mTool->getCalibration_sMt();

  CoordinateSystem csT = mSpaces->getT(mTool); //to
  CoordinateSystem csRef = mSpaces->getT(mRef); //from
  Transform3D tMref = mSpaces->get_toMfrom(csRef, csT);

  Vector3D delta_t = tMref.vector(this->get_delta_ref());
  Transform3D T_delta_t = createTransformTranslate(delta_t);

  return sMt_old * T_delta_t;
}
Exemplo n.º 4
0
void SlicePlaneClipper::updateClipPlane()
{
	if (!mSlicer)
		return;
	if (!mClipPlane)
		mClipPlane = vtkPlanePtr::New();

	Transform3D rMs = mSlicer->get_sMr().inv();

	Vector3D n = rMs.vector(this->getUnitNormal());
	Vector3D p = rMs.coord(Vector3D(0,0,0));
	mClipPlane->SetNormal(n.begin());
	mClipPlane->SetOrigin(p.begin());
}
Exemplo n.º 5
0
Vector3D CustomMetric::getVectorUp() const
{
    if(mDefineVectorUpMethod == mDefineVectorUpMethods.connectedFrameInP1)
    {
        std::vector<Transform3D> transforms = mArguments->getRefFrames();
        if (transforms.size()<2)
            return Vector3D::UnitZ();

        Transform3D rMframe = transforms[1];
        Vector3D upVector = rMframe.vector(Vector3D(-1,0,0));

        return upVector;
    }
	else if (mDefineVectorUpMethod == mDefineVectorUpMethods.tool)
	{
		Transform3D rMt = mSpaceProvider->getActiveToolTipTransform(CoordinateSystem::reference(), true);
		Vector3D toolUp = -Vector3D::UnitX();
		return rMt.vector(toolUp);
	}
	else
	{
		return mDataManager->getOperatingTable().getVectorUp();
	}
}
QString OrientationAnnotationSmartRep::determineAnnotation(Vector3D planeDir_s, Transform3D rMs)
{
	Vector3D planeDir_r = rMs.vector(planeDir_s);

	QString text;
	double threshold = cos(mAngle);
//	double threshold = 0.5;

	for (std::map<QString, Vector3D>::iterator iter=mDCMDirections_r.begin(); iter!=mDCMDirections_r.end(); ++iter)
	{
		double w = dot(planeDir_r, iter->second);
		if (w > threshold)
			text += iter->first;
	}

	return text;
//	return "test_"+qstring_cast(planeDir_s);
}