7 #include "imstkCamera.h"     8 #include "imstkColorFunction.h"     9 #include "imstkGeometryUtilities.h"    10 #include "imstkKeyboardDeviceClient.h"    11 #include "imstkKeyboardSceneControl.h"    12 #include "imstkMeshIO.h"    13 #include "imstkMouseDeviceClient.h"    14 #include "imstkMouseSceneControl.h"    16 #include "imstkPbdModel.h"    17 #include "imstkPbdModelConfig.h"    18 #include "imstkPbdObject.h"    19 #include "imstkRenderMaterial.h"    20 #include "imstkScene.h"    21 #include "imstkSceneManager.h"    22 #include "imstkSimulationManager.h"    23 #include "imstkSimulationUtils.h"    24 #include "imstkSurfaceMesh.h"    25 #include "imstkTaskGraph.h"    26 #include "imstkTaskGraphVizWriter.h"    27 #include "imstkVisualModel.h"    28 #include "imstkVTKViewer.h"    30 using namespace imstk;
    32 static std::shared_ptr<PbdObject>
    33 makeClothObj(
const std::string& name, 
double width, 
double height, 
int nRows, 
int nCols)
    35     std::shared_ptr<SurfaceMesh> clothMesh =
    37             Vec2d(width, height), Vec2i(nRows, nCols));
    41     pbdParams->
enableConstraint(PbdModelConfig::ConstraintGenType::Distance, 1e2);
    42     pbdParams->
enableConstraint(PbdModelConfig::ConstraintGenType::Dihedral, 1e1);
    44     pbdParams->
m_dt         = 0.007;
    53     clothModel->setGeometry(clothMesh);
    54     clothModel->getRenderMaterial()->setBackFaceCulling(
false);
    55     clothModel->getRenderMaterial()->setColor(Color::LightGray);
    56     clothModel->getRenderMaterial()->setDisplayMode(RenderMaterial::DisplayMode::WireframeSurface);
    59     clothSurfaceNormals->setGeometry(clothMesh);
    60     clothSurfaceNormals->getRenderMaterial()->setDisplayMode(RenderMaterial::DisplayMode::SurfaceNormals);
    61     clothSurfaceNormals->getRenderMaterial()->setPointSize(0.5);
    64     auto clothObj = std::make_shared<PbdObject>(name);
    65     clothObj->addVisualModel(clothModel);
    66     clothObj->addVisualModel(clothSurfaceNormals);
    67     clothObj->setPhysicsGeometry(clothMesh);
    68     clothObj->setDynamicalModel(pbdModel);
    69     clothObj->getPbdBody()->fixedNodeIds     = { 0, nCols - 1 };
    70     clothObj->getPbdBody()->uniformMassValue = width * height / (nRows * nCols);
    84     scene->getActiveCamera()->setFocalPoint(0.0, -5.0, 0.0);
    85     scene->getActiveCamera()->setPosition(0.0, 1.5, 25.0);
    86     scene->getActiveCamera()->setViewUp(0.0, 1.0, 0.0);
    88     std::shared_ptr<PbdObject> clothObj = makeClothObj(
"Cloth", 10.0, 10.0, 16, 16);
    89     scene->addSceneObject(clothObj);
    92     auto clothGeometry = std::dynamic_pointer_cast<
SurfaceMesh>(clothObj->getPhysicsGeometry());
    93     auto scalarsPtr    = std::make_shared<DataArray<double>>(clothGeometry->getNumVertices());
    94     std::fill_n(scalarsPtr->getPointer(), scalarsPtr->size(), 0.0);
    95     clothGeometry->setVertexScalars(
"scalars", scalarsPtr);
    98     std::shared_ptr<RenderMaterial> material = clothObj->getVisualModel(0)->getRenderMaterial();
    99     material->setScalarVisibility(
true);
   100     std::shared_ptr<ColorFunction> colorFunc = std::make_shared<ColorFunction>();
   101     colorFunc->setNumberOfColors(2);
   102     colorFunc->setColor(0, Color::Green);
   103     colorFunc->setColor(1, Color::Red);
   104     colorFunc->setColorSpace(ColorFunction::ColorSpace::RGB);
   105     colorFunc->setRange(0.0, 2.0);
   106     material->setColorLookupTable(colorFunc);
   109     connect<Event>(scene, &Scene::configureTaskGraph,
   113             std::shared_ptr<TaskGraph> graph = scene->getTaskGraph();
   118             writer->
setFileName(
"taskGraphConfigureExampleOld.svg");
   122             std::shared_ptr<TaskNode> computeVelocityScalars = std::make_shared<TaskNode>([&]()
   127                     for (
int i = 0; i < velocities.size(); i++)
   129                         scalars[i] = velocities[i].norm();
   131         }, 
"ComputeVelocityScalars");
   134             graph->insertAfter(clothObj->getUpdateGeometryNode(), computeVelocityScalars);
   137             writer->
setFileName(
"taskGraphConfigureExampleNew.svg");
   150         sceneManager->pause();
   157         std::shared_ptr<Entity> mouseAndKeyControls =
   158             SimulationUtils::createDefaultSceneControl(driver);
   159         scene->addSceneObject(mouseAndKeyControls);
 void configure(std::shared_ptr< PbdModelConfig > params)
Set simulation parameters. 
void setActiveScene(std::shared_ptr< Scene > scene) override
Set scene to be rendered. 
std::shared_ptr< SurfaceMesh > toTriangleGrid(const Vec3d ¢er, const Vec2d &size, const Vec2i &dim, const Quatd orientation=Quatd::Identity(), const double uvScale=1.0)
Produces a triangle grid on a plane given the imstkPlane. 
Base class for events which contain a type, priority, and data priority defaults to 0 and uses a grea...
void addModule(std::shared_ptr< Module > module) override
Add a module to run. 
void enableConstraint(ConstraintGenType type, const double stiffness, const int bodyId=2)
Enables a constraint of type defined by ConstraintGenType with given stiffness. If constraint of that...
void write()
Writes the graph to a file given the filename. 
void setFileName(std::string fileName)
The filename and path to write too. 
unsigned int m_iterations
Internal constraints pbd solver iterations. 
std::shared_ptr<T> obj = std::make_shared<T>(); equivalent, convenience class for STL shared allocati...
Represents a set of triangles & vertices via an array of Vec3d double vertices & Vec3i integer indice...
double m_dt
Time step size. 
void setInput(std::shared_ptr< TaskGraph > graph)
The graph to write. 
void setActiveScene(std::string newSceneName)
Sets the currently updating scene. 
static bool write(const std::shared_ptr< imstk::PointSet > imstkMesh, const std::string &filePath)
Write external file. 
static LoggerG3 & startLogger()
Starts logger with default sinks, use getInstance to create a logger with no sinks. 
Vec3d m_gravity
Gravity acceleration.