bool SceneParser::addElement(struct basicxmlnode * elementNode, Scene * scene){ if (!elementNode) { std::cout << "SceneParser::addElement: empty element node \n"; return false; } // find out element type if (std::string(elementNode->tag) == "Plane") { return addPlane(elementNode, scene); } else if (std::string(elementNode->tag) == "CirclePlane") { return addCirclePlane(elementNode, scene); } else if (std::string(elementNode->tag) == "Sphere") { return addSphere(elementNode, scene); } else if (std::string(elementNode->tag) == "Triangle") { return addTriangle(elementNode, scene); } else if (std::string(elementNode->tag) == "Quadric") { return addQuadric(elementNode, scene); } else if (std::string(elementNode->tag) == "Torus") { return addTorus(elementNode, scene); } else if (std::string(elementNode->tag) == "TriangleMesh") { return addTriangleMesh(elementNode, scene); } else { std::cout << "SceneParser::addElement: do not know how to generate \"" << elementNode->tag << "\"\n"; return false; } }
Box(Eigen::Vector4d ¢er, Eigen::Vector4d& u, Eigen::Vector4d &v, Eigen::Vector4d &w, unsigned int id, unsigned int matId, double uWidth, double vWidth, double wWidth) : QuadricCollection(center, id, matId), u(u), v(v), w(w) { BOOST_ASSERT_MSG(u[3] == 0 && v[3] == 0 && w[3] == 0, "u,v,w must have" " fourth coordinate equal to zero!");// Got u:\n" // << u << "v:\n" << v << "w:\n" << w) // Prepare rotation matrix Eigen::Matrix4d R; R.row(0) = u; R.row(1) = v; R.row(2) = w; R.row(3) = Eigen::Vector4d(0, 0, 0, 1); /* Make all the planes forming the box (centered at origin). Plane normals will be unit vectors pointing in positive/negative x, y, z directions. The points x on the plane with normal n = (a,b,c), distance d to origin satisfy n.p -d = 0, or x^T Q x = 0 where Q = |0 0 0 a/2| |0 0 0 b/2| |0 0 0 c/2| |a/2 b/2 c/2 -d| We define planes w.r.t. x, y, z axes, then rotate to u,v,w */ Eigen::Matrix4d posWPlane, negWPlane, posUPlane, negUPlane, posVPlane, negVPlane; posWPlane = negWPlane = posUPlane = negUPlane = posVPlane = negVPlane = Eigen::Matrix4d::Zero(); posUPlane.row(3) = posUPlane.col(3) = Eigen::Vector4d(0.5, 0, 0, -uWidth/2.0); negUPlane.row(3) = negUPlane.col(3) = Eigen::Vector4d(-0.5, 0, 0, -uWidth/2.0); posVPlane.row(3) = posVPlane.col(3) = Eigen::Vector4d(0, 0.5, 0, -vWidth/2.0); negVPlane.row(3) = negVPlane.col(3) = Eigen::Vector4d(0, -0.5, 0, -vWidth/2.0); posWPlane.row(3) = posWPlane.col(3) = Eigen::Vector4d(0, 0, 0.5, -wWidth/2.0); negWPlane.row(3) = negWPlane.col(3) = Eigen::Vector4d(0, 0, -0.5, -wWidth/2.0); addQuadric(R.transpose() * posWPlane * R); addQuadric(R.transpose() * negWPlane * R); addQuadric(R.transpose() * posUPlane * R); addQuadric(R.transpose() * negUPlane * R); addQuadric(R.transpose() * posVPlane * R); addQuadric(R.transpose() * negVPlane * R); }