move method setTransform() from ViewVolumeProjection to ViewProjMethod, restructure ViewProjMethod

This commit is contained in:
wmayer
2019-09-10 23:21:09 +02:00
parent ea643ec709
commit 6ebd0f4e5b
4 changed files with 77 additions and 29 deletions

View File

@@ -26,6 +26,55 @@
using namespace Base;
ViewProjMethod::ViewProjMethod()
: hasTransform(false)
{
}
/*! Calculate the composed projection matrix which is a product of
* projection matrix multiplied with input transformation matrix.
*/
Matrix4D ViewProjMethod::getComposedProjectionMatrix (void) const
{
Matrix4D mat = getProjectionMatrix();
// Compose the object transform, if defined
if (hasTransform) {
mat = mat * transform;
}
return mat;
}
/*!
* \brief This method applies an additional transformation to the input points
* passed with the () operator.
* \param mat
*/
void ViewProjMethod::setTransform(const Base::Matrix4D& mat)
{
transform = mat;
hasTransform = (mat != Base::Matrix4D());
}
void ViewProjMethod::transformInput(const Base::Vector3f& src, Base::Vector3f& dst) const
{
dst = src;
if (hasTransform) {
transform.multVec(dst, dst);
}
}
void ViewProjMethod::transformInput(const Base::Vector3d& src, Base::Vector3d& dst) const
{
dst = src;
if (hasTransform) {
transform.multVec(dst, dst);
}
}
//-----------------------------------------------------------------------------
ViewProjMatrix::ViewProjMatrix (const Matrix4D &rclMtx)
: _clMtx(rclMtx)
{
@@ -62,6 +111,7 @@ Matrix4D ViewProjMatrix::getProjectionMatrix (void) const
mat.move(-0.5, -0.5, -0.5);
mat.scale(2.0, 2.0, 2.0);
}
return mat;
}
@@ -78,8 +128,11 @@ void perspectiveTransform(const Base::Matrix4D& mat, Vec& pnt)
pnt /= w;
}
Vector3f ViewProjMatrix::operator()(const Vector3f& src) const
Vector3f ViewProjMatrix::operator()(const Vector3f& inp) const
{
Vector3f src;
transformInput(inp, src);
Vector3f dst;
if (!isOrthographic) {
dst = src;
@@ -93,8 +146,11 @@ Vector3f ViewProjMatrix::operator()(const Vector3f& src) const
return dst;
}
Vector3d ViewProjMatrix::operator()(const Vector3d& src) const
Vector3d ViewProjMatrix::operator()(const Vector3d& inp) const
{
Vector3d src;
transformInput(inp, src);
Vector3d dst;
if (!isOrthographic) {
dst = src;

View File

@@ -47,10 +47,23 @@ public:
/** Convert a 2D point on the projection plane in 3D space */
virtual Vector3d inverse (const Vector3d &rclPt) const = 0;
/** Calculate the projection (+ mapping) matrix */
virtual Matrix4D getProjectionMatrix (void) const = 0;
virtual Matrix4D getProjectionMatrix (void) const = 0;
/** Calculate the composed projection matrix */
Matrix4D getComposedProjectionMatrix (void) const;
/** Apply an additional transformation to the input points */
void setTransform(const Base::Matrix4D&);
const Base::Matrix4D& getTransform() const {
return transform;
}
protected:
ViewProjMethod(){}
ViewProjMethod();
void transformInput(const Base::Vector3f&, Base::Vector3f&) const;
void transformInput(const Base::Vector3d&, Base::Vector3d&) const;
private:
bool hasTransform;
Base::Matrix4D transform;
};
/**

View File

@@ -39,7 +39,6 @@ using namespace Gui;
ViewVolumeProjection::ViewVolumeProjection (const SbViewVolume &vv)
: viewVolume(vv)
, hasTransform(false)
{
matrix = viewVolume.getMatrix();
invert = matrix.inverse();
@@ -47,11 +46,10 @@ ViewVolumeProjection::ViewVolumeProjection (const SbViewVolume &vv)
Base::Vector3f ViewVolumeProjection::operator()(const Base::Vector3f &pt) const
{
SbVec3f pt3d(pt.x,pt.y,pt.z);
if (hasTransform) {
Base::Vector3f ptt = transform * pt;
pt3d.setValue(ptt.x, ptt.y, ptt.z);
}
Base::Vector3f src;
transformInput(pt, src);
SbVec3f pt3d(src.x,src.y,src.z);
// See SbViewVolume::projectToScreen
matrix.multVecMatrix(pt3d, pt3d);
@@ -80,17 +78,6 @@ Base::Vector3d ViewVolumeProjection::inverse (const Base::Vector3d &pt) const
return Base::convertTo<Base::Vector3d>(ptf);
}
/*!
* \brief This method applies an additional transformation to the input points
* passed with the () operator.
* \param mat
*/
void ViewVolumeProjection::setTransform(const Base::Matrix4D& mat)
{
transform = mat;
hasTransform = (mat != Base::Matrix4D());
}
Base::Matrix4D ViewVolumeProjection::getProjectionMatrix () const
{
// Inventor stores the transposed matrix
@@ -101,11 +88,6 @@ Base::Matrix4D ViewVolumeProjection::getProjectionMatrix () const
mat[i][j] = matrix[j][i];
}
// Compose the object transform, if defined
if (hasTransform) {
mat = mat * transform;
}
return mat;
}

View File

@@ -121,15 +121,12 @@ public:
Base::Vector3f inverse (const Base::Vector3f &rclPt) const;
Base::Vector3d inverse (const Base::Vector3d &rclPt) const;
void setTransform(const Base::Matrix4D&);
Base::Matrix4D getProjectionMatrix () const;
protected:
SbViewVolume viewVolume;
SbMatrix matrix;
SbMatrix invert;
bool hasTransform;
Base::Matrix4D transform;
};
class GuiExport Tessellator