GLC_Point2d GLC_Viewport::project(const GLC_Point3d &point, bool useCameraMatrix) const { GLC_Matrix4x4 modelView; GLC_Matrix4x4 projectionMatrix; GLint viewport[4]= {0, 0, m_Width, m_Height}; if (useCameraMatrix) { modelView= m_pViewCam->modelViewMatrix(); projectionMatrix= m_ProjectionMatrix; } else { modelView= GLC_Context::current()->modelViewMatrix(); glGetIntegerv(GL_VIEWPORT, viewport); projectionMatrix= GLC_Context::current()->projectionMatrix(); } double x; double y; double z; glc::gluProject(point.x(), point.y(), point.z(), modelView.getData(), projectionMatrix.getData(), viewport, &x, &y, &z); GLC_Vector2d subject; subject.setX(x); subject.setY(y); return subject; }
QList<GLC_Point2d> GLC_Viewport::project(const QList<GLC_Point3d> &points, bool useCameraMatrix) const { QList<GLC_Point2d> subject; GLC_Matrix4x4 modelView; GLC_Matrix4x4 projectionMatrix; GLint viewport[4]= {0, 0, m_Width, m_Height}; if (useCameraMatrix) { modelView= m_pViewCam->modelViewMatrix(); projectionMatrix= m_ProjectionMatrix; } else { modelView= GLC_Context::current()->modelViewMatrix(); glGetIntegerv(GL_VIEWPORT, viewport); projectionMatrix= GLC_Context::current()->projectionMatrix(); } double x; double y; double z; const int count= points.count(); for (int i= 0; i < count; ++i) { const GLC_Point3d point= points.at(i); glc::gluProject(point.x(), point.y(), point.z(), modelView.getData(), projectionMatrix.getData(), viewport, &x, &y, &z); subject.append(GLC_Point2d(x, y)); } return subject; }
GLC_Point3d GLC_Viewport::unproject(int x, int y, GLenum buffer, bool onGeometry) const { GLC_Point3d subject; // Z Buffer component of the given coordinate is between 0 and 1 GLfloat Depth; // read selected point glReadBuffer(buffer); glReadPixels(x, m_Height - y , 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &Depth); // if on geometry mode and the point is not on geometry return null point if (!qFuzzyCompare(Depth, 1.0f) || !onGeometry) { // The current viewport opengl definition GLint viewport[4]= {0, 0, m_Width, m_Height}; // OpenGL ccordinate of selected point GLdouble pX, pY, pZ; glc::gluUnProject((GLdouble) x, (GLdouble) (m_Height - y) , Depth , m_pViewCam->modelViewMatrix().getData(), m_ProjectionMatrix.getData(), viewport, &pX, &pY, &pZ); subject.setVect(pX, pY, pZ); } return subject; }
GLC_uint GLC_PointCloud::addPoint(const QList<GLC_Point3d>& pointsList) { const int pointCount= pointsList.size(); const int size= pointCount * 3; GLfloatVector data(size); for (int i= 0; i < pointCount; ++i) { const GLC_Point3d currentPoint(pointsList.at(i)); data[i * 3]= static_cast<float>(currentPoint.x()); data[i * 3 + 1]= static_cast<float>(currentPoint.y()); data[i * 3 + 2]= static_cast<float>(currentPoint.z()); } return GLC_Geometry::m_WireData.addVerticeGroup(data); }
void GLC_OctreeNode::addChildren() { Q_ASSERT(m_Children.isEmpty()); Q_ASSERT(!m_BoundingBox.isEmpty()); const double xLower= m_BoundingBox.lowerCorner().x(); const double yLower= m_BoundingBox.lowerCorner().y(); const double zLower= m_BoundingBox.lowerCorner().z(); const double xUpper= m_BoundingBox.upperCorner().x(); const double dX= (xUpper - xLower) / 2.0; const double yUpper= m_BoundingBox.upperCorner().y(); const double dY= (yUpper - yLower) / 2.0; const double zUpper= m_BoundingBox.upperCorner().z(); const double dZ= (zUpper - zLower) / 2.0; // Add 8 Children GLC_Point3d lower; GLC_Point3d upper; GLC_OctreeNode* pOctreeNode= NULL; { // Child 1 lower.setVect(xLower, yLower, zLower); upper.setVect(xLower + dX, yLower + dY, zLower + dZ); GLC_BoundingBox box(lower, upper); pOctreeNode= new GLC_OctreeNode(box, this); m_Children.append(pOctreeNode); } { // Child 2 lower.setVect(xLower + dX, yLower, zLower); upper.setVect(xUpper, yLower + dY, zLower + dZ); GLC_BoundingBox box(lower, upper); pOctreeNode= new GLC_OctreeNode(box, this); m_Children.append(pOctreeNode); } { // Child 3 lower.setVect(xLower + dX, yLower + dY, zLower); upper.setVect(xUpper, yUpper, zLower + dZ); GLC_BoundingBox box(lower, upper); pOctreeNode= new GLC_OctreeNode(box, this); m_Children.append(pOctreeNode); } { // Child 4 lower.setVect(xLower, yLower + dY, zLower); upper.setVect(xLower + dX, yUpper, zLower + dZ); GLC_BoundingBox box(lower, upper); pOctreeNode= new GLC_OctreeNode(box, this); m_Children.append(pOctreeNode); } { // Child 5 lower.setVect(xLower, yLower, zLower + dZ); upper.setVect(xLower + dX, yLower + dY, zUpper); GLC_BoundingBox box(lower, upper); pOctreeNode= new GLC_OctreeNode(box, this); m_Children.append(pOctreeNode); } { // Child 6 lower.setVect(xLower + dX, yLower, zLower + dZ); upper.setVect(xUpper, yLower + dY, zUpper); GLC_BoundingBox box(lower, upper); pOctreeNode= new GLC_OctreeNode(box, this); m_Children.append(pOctreeNode); } { // Child 7 lower.setVect(xLower + dX, yLower + dY, zLower + dZ); upper.setVect(xUpper, yUpper, zUpper); GLC_BoundingBox box(lower, upper); pOctreeNode= new GLC_OctreeNode(box, this); m_Children.append(pOctreeNode); } { // Child 8 lower.setVect(xLower, yLower + dY, zLower + dZ); upper.setVect(xLower + dX, yUpper, zUpper); GLC_BoundingBox box(lower, upper); pOctreeNode= new GLC_OctreeNode(box, this); m_Children.append(pOctreeNode); } }