void beam::calc() { double k=leng/100.0; for(int i=0;i<101;i++){ bend[i]=bending(i*k); Fsy[i]=neili(i*k); innerMz[i]=wanju(i*k); } }
bool ThinPlateRenderer::visualization() { if (!this->m_provider) { _GT_LOGGER_ERR(this->name(), "Subroutine <visualization> failed. Missing provider."); return (false); } if (!this->m_provider->model()) { _GT_LOGGER_ERR(this->name(), "Subroutine <visualization> failed. Missing model."); return (false); } const openmesh::Mesh &mesh(this->m_provider->model()->mesh()); const ThinPlateProvider *provider = (const ThinPlateProvider *)this->m_provider; const Provider::Vertices::DataType &control_vertices(provider->controlVertices().data()); const eigen::Matrix &weight(provider->weight()); const eigen::Matrix &transformation(provider->transformation()); osg::ref_ptr<osg::Group> group = new osg::Group(); // Computes bending coordinates. eigen::Matrix3xN coordinates(3, mesh.n_vertices()); eigen::Vector dists(control_vertices.size()); eigen::Vector coord = eigen::Vector::Ones(4); for (size_t i = 0; i < mesh.n_vertices(); ++i) { const openmesh::Point &point(mesh.point(mesh.vertex_handle(i))); for (size_t j = 0; j < control_vertices.size(); ++j) { dists(j) = (point - mesh.point(mesh.vertex_handle(control_vertices[j]))).length(); } coord.bottomRows<3>() = algo::Util::toVector3(point); eigen::Vector bending = coord.transpose() * transformation - dists.transpose() * weight; coordinates.col(i) = bending.bottomRows<3>() / bending(0); } // Builds mesh with vertex positions representing bending coordinates. osg::ref_ptr<osg::Vec3Array> model_vertex_array = new osg::Vec3Array(); model_vertex_array->reserve(mesh.n_vertices()); osg::ref_ptr<osg::Vec3Array> model_normal_array = new osg::Vec3Array(); model_normal_array->reserve(mesh.n_vertices()); for (openmesh::Mesh::ConstVertexIter cv_iter = mesh.vertices_begin(); cv_iter != mesh.vertices_end(); ++cv_iter) { model_vertex_array->push_back(algo::Util::toVec3(coordinates.col(cv_iter.handle().idx()))); model_normal_array->push_back(algo::Util::toVec3(mesh.normal(cv_iter.handle()))); } osg::ref_ptr<osg::Vec4Array> model_color_array = new osg::Vec4Array(); model_color_array->push_back(osg::Vec4(1.0f, 0.0f, 0.0f, 0.0f)); osg::ref_ptr<osg::DrawElementsUInt> model_primitives = new osg::DrawElementsUInt(osg::PrimitiveSet::Mode::TRIANGLES, 0); model_primitives->reserve(mesh.n_faces() * 3); for (openmesh::Mesh::ConstFaceIter cf_iter = mesh.faces_begin(); cf_iter != mesh.faces_end(); ++cf_iter) { openmesh::Mesh::ConstFaceVertexIter cfv_iter = mesh.cfv_iter(cf_iter.handle()); model_primitives->push_back(( cfv_iter).handle().idx()); model_primitives->push_back((++cfv_iter).handle().idx()); model_primitives->push_back((++cfv_iter).handle().idx()); } osg::ref_ptr<osg::Geometry> model_geometry = new osg::Geometry(); model_geometry->setVertexArray(model_vertex_array); model_geometry->setNormalArray(model_normal_array); model_geometry->setNormalBinding(osg::Geometry::AttributeBinding::BIND_PER_VERTEX); model_geometry->setColorArray(model_color_array); model_geometry->setColorBinding(osg::Geometry::AttributeBinding::BIND_OVERALL); model_geometry->addPrimitiveSet(model_primitives); osg::ref_ptr<osg::Geode> model_geode = new osg::Geode(); model_geode->addDrawable(model_geometry); group->addChild(model_geode); // Appends mesh faces. osg::ref_ptr<osg::Material> mesh_material = new osg::Material(); mesh_material->setAmbient(osg::Material::Face::FRONT_AND_BACK, osg::Vec4(0.0f, 1.0f, 0.0f, 1.0f)); mesh_material->setDiffuse(osg::Material::Face::FRONT_AND_BACK, osg::Vec4(0.0f, 1.0f, 0.0f, 1.0f)); mesh_material->setSpecular(osg::Material::Face::FRONT_AND_BACK, osg::Vec4(0.0f, 0.0f, 0.0f, 1.0f)); mesh_material->setEmission(osg::Material::Face::FRONT_AND_BACK, osg::Vec4(0.0f, 0.0f, 0.0f, 0.0f)); mesh_material->setShininess(osg::Material::Face::FRONT_AND_BACK, 1.0f); osg::ref_ptr<osg::Group> mesh_group = new osg::Group(); mesh_group->addChild(provider->model()->node().faces()); mesh_group->getOrCreateStateSet()->setAttribute(mesh_material, osg::StateAttribute::Values::ON | osg::StateAttribute::Values::OVERRIDE); group->addChild(mesh_group); this->m_node->removeChildren(0, this->m_node->getNumChildren()); this->m_node->addChild(group); this->m_node->dirtyBound(); return (true); }