Exemplo n.º 1
0
	void Mesh::commitTransformations()
	{
		glm::mat4x4 newModMatrix;
		glm::mat4x4 newNormModMatrix;
		transformMat(m_translation, m_rotation, m_scale, newModMatrix);
		transformMat(glm::vec3(), m_rotation, 1.0f / m_scale, newNormModMatrix);
		glm::mat4x4 invModMatrix = glm::inverse(m_modMatrix);
		glm::mat4x4 invNormModMatrix = glm::inverse(m_normModMatrix);
		glm::mat4x4 combinedMatrix = newModMatrix * invModMatrix;
		glm::mat4x4 combinedNormMatrix = newNormModMatrix * invNormModMatrix;
		m_modMatrix = newModMatrix;
		m_normModMatrix = newNormModMatrix;
		for (Triangle * t : m_triangles) {
			for (int i = 0; i < 3; ++i) {
				Vertex v = t->getVertex(i);
				glm::vec4 newVec = glm::vec4(v.position, 1);
				newVec = combinedMatrix * newVec;
				v.position = glm::vec3(newVec);
				newVec = glm::vec4(v.normal, 1);
				newVec = combinedNormMatrix * newVec;
				v.normal = glm::normalize(glm::vec3(newVec));
				t->setVertex(i, v);
			}
			t->commitTransformations();
		}
	}
Exemplo n.º 2
0
void Resampler::resample(const ::fwData::Image::csptr& _inImage,
                         const ::fwData::Image::sptr& _outImage,
                         const ::fwData::TransformationMatrix3D::csptr& _trf,
                         const ::fwData::Image::csptr& _targetImg)
{
    const itk::Matrix<double, 4, 4 > itkMatrix = ::fwItkIO::helper::Transform::convertToITK(_trf);

    // We need to extract a 3x3 matrix and a vector to set the affine transform.
    itk::Matrix<double, 3, 3> transformMat;

    for(std::uint8_t i = 0; i < 3; ++i)
    {
        for(std::uint8_t j = 0; j < 3; ++j)
        {
            transformMat(i, j) = itkMatrix(i, j);
        }
    }

    itk::Vector<double, 3> translation;
    for(std::uint8_t i = 0; i < 3; ++i)
    {
        // Extract the last column to get the translation.
        translation.SetElement(i, itkMatrix(i, 3));
    }

    itk::AffineTransform<double, 3>::Pointer transf = itk::AffineTransform<double, 3>::New();
    transf->SetMatrix(transformMat);
    transf->SetTranslation(translation);

    Resampling::Parameters params;
    params.i_image       = _inImage;
    params.o_image       = _outImage;
    params.i_trf         = transf.GetPointer();
    params.i_targetImage = _targetImg;

    const ::fwTools::DynamicType type = _inImage->getPixelType();
    ::fwTools::Dispatcher< ::fwTools::IntrinsicTypes, Resampling >::invoke(type, params);
}