Skip to content

Commit 7b9df19

Browse files
committed
add checker for collision consistency
1 parent 3357b67 commit 7b9df19

File tree

3 files changed

+160
-0
lines changed

3 files changed

+160
-0
lines changed

applications/projects/SceneChecking/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ set(HEADER_FILES
1212
${SCENECHECK_SRC_DIR}/config.h.in
1313
${SCENECHECK_SRC_DIR}/init.h
1414
${SCENECHECK_SRC_DIR}/SceneCheckAPIChange.h
15+
${SCENECHECK_SRC_DIR}/SceneCheckCollisionPipelineAndModels.h
1516
${SCENECHECK_SRC_DIR}/SceneCheckCollisionResponse.h
1617
${SCENECHECK_SRC_DIR}/SceneCheckDeprecatedComponents.h
1718
${SCENECHECK_SRC_DIR}/SceneCheckDuplicatedName.h
@@ -26,6 +27,7 @@ set(HEADER_FILES
2627
set(SOURCE_FILES
2728
${SCENECHECK_SRC_DIR}/init.cpp
2829
${SCENECHECK_SRC_DIR}/SceneCheckAPIChange.cpp
30+
${SCENECHECK_SRC_DIR}/SceneCheckCollisionPipelineAndModels.cpp
2931
${SCENECHECK_SRC_DIR}/SceneCheckCollisionResponse.cpp
3032
${SCENECHECK_SRC_DIR}/SceneCheckDeprecatedComponents.cpp
3133
${SCENECHECK_SRC_DIR}/SceneCheckDuplicatedName.cpp
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/******************************************************************************
2+
* SOFA, Simulation Open-Framework Architecture *
3+
* (c) 2006 INRIA, USTL, UJF, CNRS, MGH *
4+
* *
5+
* This program is free software; you can redistribute it and/or modify it *
6+
* under the terms of the GNU Lesser General Public License as published by *
7+
* the Free Software Foundation; either version 2.1 of the License, or (at *
8+
* your option) any later version. *
9+
* *
10+
* This program is distributed in the hope that it will be useful, but WITHOUT *
11+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
12+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
13+
* for more details. *
14+
* *
15+
* You should have received a copy of the GNU Lesser General Public License *
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
17+
*******************************************************************************
18+
* Authors: The SOFA Team and external contributors (see Authors.txt) *
19+
* *
20+
* Contact information: contact@sofa-framework.org *
21+
******************************************************************************/
22+
#include "SceneCheckCollisionPipelineAndModels.h"
23+
24+
#include <sofa/simulation/Node.h>
25+
#include <sofa/core/CollisionModel.h>
26+
#include <sofa/core/collision/Pipeline.h>
27+
#include <sofa/simulation/SceneCheckMainRegistry.h>
28+
29+
namespace sofa::_scenechecking_
30+
{
31+
32+
const bool SceneCheckCollisionPipelineAndModelsRegistered = sofa::simulation::SceneCheckMainRegistry::addToRegistry(SceneCheckCollisionPipelineAndModels::newSPtr());
33+
34+
using sofa::simulation::Node;
35+
36+
const std::string SceneCheckCollisionPipelineAndModels::getName()
37+
{
38+
return "SceneCheckCollisionPipelineAndModels";
39+
}
40+
41+
const std::string SceneCheckCollisionPipelineAndModels::getDesc()
42+
{
43+
return "Ensure the consistency of the existence of a collision pipeline, and collision models in the scene.";
44+
}
45+
46+
void SceneCheckCollisionPipelineAndModels::doInit(Node* node)
47+
{
48+
SOFA_UNUSED(node);
49+
}
50+
51+
void SceneCheckCollisionPipelineAndModels::doCheckOn(Node* node)
52+
{
53+
const sofa::core::objectmodel::BaseContext* root = node->getContext()->getRootContext();
54+
55+
if(!root)
56+
{
57+
return;
58+
}
59+
60+
sofa::core::collision::Pipeline::SPtr anyPipeline{};
61+
root->get(anyPipeline, sofa::core::objectmodel::BaseContext::SearchDirection::SearchDown);
62+
sofa::core::CollisionModel::SPtr anyCollisionModel{};
63+
root->get(anyCollisionModel, sofa::core::objectmodel::BaseContext::SearchDirection::SearchDown);
64+
65+
if(anyPipeline)
66+
{
67+
if(anyCollisionModel)
68+
{
69+
// there is a collision pipeline and (at least one) collision model(s), carry on.
70+
}
71+
else
72+
{
73+
// there is a collision pipeline but no collision model.
74+
// Either the collision pipeline is superfluous;
75+
// or the collision model(s) has been forgotten.
76+
m_message = "There is no collision model in this scene, but there is a collision pipeline. Either add one collision model or remove the collision pipeline.";
77+
}
78+
}
79+
else
80+
{
81+
if(anyCollisionModel)
82+
{
83+
// At least one collision model has been detected but without any pipeline.
84+
// Either the collision pipeline has been forgotten;
85+
// or the collision model(s) is useless.
86+
m_message = "At least one collision model has been found, but there is no collision pipeline. You may add a collision pipeline (or remove the collision model if it is not used).";
87+
}
88+
else
89+
{
90+
// there is no collision pipeline and no collision model, the scene certainly does not involve any collision feature.
91+
}
92+
}
93+
}
94+
95+
void SceneCheckCollisionPipelineAndModels::doPrintSummary()
96+
{
97+
if(!m_message.empty())
98+
{
99+
msg_warning(this->getName()) << m_message;
100+
}
101+
}
102+
103+
104+
} // namespace sofa::_scenechecking_
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/******************************************************************************
2+
* SOFA, Simulation Open-Framework Architecture *
3+
* (c) 2006 INRIA, USTL, UJF, CNRS, MGH *
4+
* *
5+
* This program is free software; you can redistribute it and/or modify it *
6+
* under the terms of the GNU Lesser General Public License as published by *
7+
* the Free Software Foundation; either version 2.1 of the License, or (at *
8+
* your option) any later version. *
9+
* *
10+
* This program is distributed in the hope that it will be useful, but WITHOUT *
11+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
12+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
13+
* for more details. *
14+
* *
15+
* You should have received a copy of the GNU Lesser General Public License *
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
17+
*******************************************************************************
18+
* Authors: The SOFA Team and external contributors (see Authors.txt) *
19+
* *
20+
* Contact information: contact@sofa-framework.org *
21+
******************************************************************************/
22+
#pragma once
23+
24+
#include <SceneChecking/config.h>
25+
#include <sofa/simulation/SceneCheck.h>
26+
27+
#include <map>
28+
#include <sstream>
29+
30+
namespace sofa::_scenechecking_
31+
{
32+
33+
class SOFA_SCENECHECKING_API SceneCheckCollisionPipelineAndModels : public sofa::simulation::SceneCheck
34+
{
35+
public:
36+
virtual ~SceneCheckCollisionPipelineAndModels() {}
37+
typedef std::shared_ptr<SceneCheckCollisionPipelineAndModels> SPtr;
38+
static SPtr newSPtr() { return SPtr(new SceneCheckCollisionPipelineAndModels()); }
39+
virtual const std::string getName() override;
40+
virtual const std::string getDesc() override;
41+
void doInit(sofa::simulation::Node* node) override;
42+
void doCheckOn(sofa::simulation::Node* node) override;
43+
void doPrintSummary() override;
44+
45+
private:
46+
std::string m_message;
47+
};
48+
49+
} // namespace sofa::_scenechecking_
50+
51+
namespace sofa::scenechecking
52+
{
53+
using _scenechecking_::SceneCheckCollisionPipelineAndModels;
54+
}

0 commit comments

Comments
 (0)