Gui: harmonize classes View3DInventorViewer and View3DInventorPy
This commit is contained in:
@@ -2597,7 +2597,7 @@ SbRotation View3DInventorViewer::getCameraOrientation() const
|
||||
return cam->orientation.getValue();
|
||||
}
|
||||
|
||||
SbVec3f View3DInventorViewer::getPointOnScreen(const SbVec2s& pnt) const
|
||||
SbVec3f View3DInventorViewer::getPointOnFocalPlane(const SbVec2s& pnt) const
|
||||
{
|
||||
const SbViewportRegion& vp = this->getSoRenderManager()->getViewportRegion();
|
||||
|
||||
@@ -2642,6 +2642,22 @@ SbVec3f View3DInventorViewer::getPointOnScreen(const SbVec2s& pnt) const
|
||||
return pt;
|
||||
}
|
||||
|
||||
SbVec2s View3DInventorViewer::getPointOnScreen(const SbVec3f& pnt) const
|
||||
{
|
||||
const SbViewportRegion& vp = this->getSoRenderManager()->getViewportRegion();
|
||||
float fRatio = vp.getViewportAspectRatio();
|
||||
const SbVec2s& sp = vp.getViewportSizePixels();
|
||||
SbViewVolume vv = this->getSoRenderManager()->getCamera()->getViewVolume(fRatio);
|
||||
|
||||
SbVec3f pt(pnt);
|
||||
vv.projectToScreen(pt, pt);
|
||||
|
||||
short x = short(std::roundf(pt[0] * sp[0]));
|
||||
short y = short(std::roundf(pt[1] * sp[1]));
|
||||
|
||||
return SbVec2s(x, y);
|
||||
}
|
||||
|
||||
void View3DInventorViewer::getNearPlane(SbVec3f& rcPt, SbVec3f& rcNormal) const
|
||||
{
|
||||
SoCamera* pCam = getSoRenderManager()->getCamera();
|
||||
|
||||
@@ -295,7 +295,9 @@ public:
|
||||
/** Returns the orientation of the camera. */
|
||||
SbRotation getCameraOrientation() const;
|
||||
/** Returns the 3d point on the focal plane to the given 2d point. */
|
||||
SbVec3f getPointOnScreen(const SbVec2s&) const;
|
||||
SbVec3f getPointOnFocalPlane(const SbVec2s&) const;
|
||||
/** Returns the 2d coordinates on the screen to the given 3d point. */
|
||||
SbVec2s getPointOnScreen(const SbVec3f&) const;
|
||||
/** Returns the near plane represented by its normal and base point. */
|
||||
void getNearPlane(SbVec3f& rcPt, SbVec3f& rcNormal) const;
|
||||
/** Returns the far plane represented by its normal and base point. */
|
||||
|
||||
@@ -125,7 +125,7 @@ void View3DInventorPy::init_type()
|
||||
add_varargs_method("saveVectorGraphic",&View3DInventorPy::saveVectorGraphic,"saveVectorGraphic()");
|
||||
add_varargs_method("getCamera",&View3DInventorPy::getCamera,"getCamera()");
|
||||
add_varargs_method("getCameraNode",&View3DInventorPy::getCameraNode,"getCameraNode()");
|
||||
add_varargs_method("getViewDirection",&View3DInventorPy::getViewDirection,"getViewDirection() --> tuple of integers\n"
|
||||
add_varargs_method("getViewDirection",&View3DInventorPy::getViewDirection,"getViewDirection() --> tuple of floats\n"
|
||||
"returns the direction vector the view is currently pointing at as tuple with xyz values\n"
|
||||
);
|
||||
add_varargs_method("setViewDirection",&View3DInventorPy::setViewDirection,"setViewDirection(tuple) --> None\n"
|
||||
@@ -155,8 +155,10 @@ void View3DInventorPy::init_type()
|
||||
"\n"
|
||||
"Does the same as getObjectInfo() but returns a list of dictionaries or None.\n");
|
||||
add_varargs_method("getSize",&View3DInventorPy::getSize,"getSize()");
|
||||
add_varargs_method("getPoint",&View3DInventorPy::getPoint,
|
||||
"getPoint(pixel coords (as integer)) -> 3D vector\n"
|
||||
add_varargs_method("getPoint",&View3DInventorPy::getPointOnFocalPlane,
|
||||
"Same as getPointOnFocalPlane");
|
||||
add_varargs_method("getPointOnFocalPlane",&View3DInventorPy::getPointOnFocalPlane,
|
||||
"getPointOnFocalPlane(pixel coords (as integer)) -> 3D vector\n"
|
||||
"\n"
|
||||
"Return the according 3D point on the focal plane to the given 2D point (in\n"
|
||||
"pixel coordinates).\n");
|
||||
@@ -1654,7 +1656,7 @@ Py::Object View3DInventorPy::getSize(const Py::Tuple& args)
|
||||
}
|
||||
}
|
||||
|
||||
Py::Object View3DInventorPy::getPoint(const Py::Tuple& args)
|
||||
Py::Object View3DInventorPy::getPointOnFocalPlane(const Py::Tuple& args)
|
||||
{
|
||||
short x,y;
|
||||
if (!PyArg_ParseTuple(args.ptr(), "hh", &x, &y)) {
|
||||
@@ -1664,7 +1666,7 @@ Py::Object View3DInventorPy::getPoint(const Py::Tuple& args)
|
||||
y = (int)Py::Int(t[1]);
|
||||
}
|
||||
try {
|
||||
SbVec3f pt = getView3DIventorPtr()->getViewer()->getPointOnScreen(SbVec2s(x,y));
|
||||
SbVec3f pt = getView3DIventorPtr()->getViewer()->getPointOnFocalPlane(SbVec2s(x,y));
|
||||
return Py::Vector(Base::Vector3f(pt[0], pt[1], pt[2]));
|
||||
}
|
||||
catch (const Base::Exception& e) {
|
||||
@@ -1693,27 +1695,10 @@ Py::Object View3DInventorPy::getPointOnScreen(const Py::Tuple& args)
|
||||
}
|
||||
|
||||
try {
|
||||
const SbViewportRegion& vp = getView3DIventorPtr()->getViewer()->getSoRenderManager()->getViewportRegion();
|
||||
float fRatio = vp.getViewportAspectRatio();
|
||||
const SbVec2s& sp = vp.getViewportSizePixels();
|
||||
//float dX, dY; vp.getViewportSize().getValue(dX, dY);
|
||||
SbViewVolume vv = getView3DIventorPtr()->getViewer()->getSoRenderManager()->getCamera()->getViewVolume(fRatio);
|
||||
|
||||
SbVec3f pt(vx,vy,vz);
|
||||
vv.projectToScreen(pt, pt);
|
||||
|
||||
//if (fRatio > 1.0f) {
|
||||
// pt[0] = (pt[0] - 0.5f*dX) / fRatio + 0.5f*dX;
|
||||
//}
|
||||
//else {
|
||||
// pt[1] = (pt[1] - 0.5f*dY) * fRatio + 0.5f*dY;
|
||||
//}
|
||||
|
||||
int x = pt[0] * sp[0];
|
||||
int y = pt[1] * sp[1];
|
||||
SbVec2s pt = getView3DIventorPtr()->getViewer()->getPointOnScreen(SbVec3f(vx,vy,vz));
|
||||
Py::Tuple tuple(2);
|
||||
tuple.setItem(0, Py::Int(x));
|
||||
tuple.setItem(1, Py::Int(y));
|
||||
tuple.setItem(0, Py::Int(pt[0]));
|
||||
tuple.setItem(1, Py::Int(pt[1]));
|
||||
|
||||
return tuple;
|
||||
}
|
||||
|
||||
@@ -114,7 +114,7 @@ public:
|
||||
Py::Object getObjectInfo(const Py::Tuple&);
|
||||
Py::Object getObjectsInfo(const Py::Tuple&);
|
||||
Py::Object getSize(const Py::Tuple&);
|
||||
Py::Object getPoint(const Py::Tuple&);
|
||||
Py::Object getPointOnFocalPlane(const Py::Tuple&);
|
||||
Py::Object getPointOnScreen(const Py::Tuple&);
|
||||
Py::Object addEventCallback(const Py::Tuple&);
|
||||
Py::Object removeEventCallback(const Py::Tuple&);
|
||||
|
||||
@@ -71,7 +71,8 @@ void View3DInventorViewerPy::init_type()
|
||||
);
|
||||
add_varargs_method("setFocalDistance",&View3DInventorViewerPy::setFocalDistance,"setFocalDistance(float) -> None\n");
|
||||
add_varargs_method("getFocalDistance",&View3DInventorViewerPy::getFocalDistance,"getFocalDistance() -> float\n");
|
||||
add_varargs_method("getPoint", &View3DInventorViewerPy::getPoint, "getPoint(x, y) -> Base::Vector(x,y,z)");
|
||||
add_varargs_method("getPoint", &View3DInventorViewerPy::getPointOnFocalPlane, "Same as getPointOnFocalPlane");
|
||||
add_varargs_method("getPointOnFocalPlane", &View3DInventorViewerPy::getPointOnFocalPlane, "getPointOnFocalPlane(x, y) -> Base::Vector(x,y,z)");
|
||||
add_varargs_method("getPickRadius", &View3DInventorViewerPy::getPickRadius,
|
||||
"getPickRadius(): returns radius of confusion in pixels for picking objects on screen (selection).");
|
||||
add_varargs_method("setPickRadius", &View3DInventorViewerPy::setPickRadius,
|
||||
@@ -319,7 +320,7 @@ Py::Object View3DInventorViewerPy::getFocalDistance(const Py::Tuple& args)
|
||||
}
|
||||
}
|
||||
|
||||
Py::Object View3DInventorViewerPy::getPoint(const Py::Tuple& args)
|
||||
Py::Object View3DInventorViewerPy::getPointOnFocalPlane(const Py::Tuple& args)
|
||||
{
|
||||
short x,y;
|
||||
if (!PyArg_ParseTuple(args.ptr(), "hh", &x, &y)) {
|
||||
@@ -329,7 +330,7 @@ Py::Object View3DInventorViewerPy::getPoint(const Py::Tuple& args)
|
||||
y = (int)Py::Int(t[1]);
|
||||
}
|
||||
try {
|
||||
SbVec3f pt = _viewer->getPointOnScreen(SbVec2s(x,y));
|
||||
SbVec3f pt = _viewer->getPointOnFocalPlane(SbVec2s(x,y));
|
||||
return Py::Vector(Base::Vector3f(pt[0], pt[1], pt[2]));
|
||||
}
|
||||
catch (const Base::Exception& e) {
|
||||
|
||||
@@ -61,7 +61,7 @@ public:
|
||||
Py::Object seekToPoint(const Py::Tuple&);
|
||||
Py::Object setFocalDistance(const Py::Tuple& args);
|
||||
Py::Object getFocalDistance(const Py::Tuple& args);
|
||||
Py::Object getPoint(const Py::Tuple& args);
|
||||
Py::Object getPointOnFocalPlane(const Py::Tuple& args);
|
||||
Py::Object getPickRadius(const Py::Tuple& args);
|
||||
Py::Object setPickRadius(const Py::Tuple& args);
|
||||
|
||||
|
||||
@@ -329,8 +329,8 @@ double Grabber3d::getViewerScale(Gui::View3DInventorViewer* viewer)
|
||||
|
||||
SbVec2s p1s(0,0);
|
||||
SbVec2s p2s(winSizePx[0] - 1, winSizePx[1] - 1);
|
||||
SbVec3f p1w = viewer->getPointOnScreen(p1s);
|
||||
SbVec3f p2w = viewer->getPointOnScreen(p2s);
|
||||
SbVec3f p1w = viewer->getPointOnFocalPlane(p1s);
|
||||
SbVec3f p2w = viewer->getPointOnFocalPlane(p2s);
|
||||
double worldLengthmm = (p2w - p1w).length(); //mm
|
||||
|
||||
result = worldLengthmm / screenLengthmm;
|
||||
|
||||
Reference in New Issue
Block a user