Verified Commit 4934af2d authored by Marc SCHWEITZER's avatar Marc SCHWEITZER 🚴
Browse files

feat(viz): add optional name to SAxis adaptor

* if name is set, it will be displayed at axis origin
* Update Tuto15Matrix to display name to first SAxis, also reset camera at startup
parent 27ad19e3
...@@ -46,6 +46,7 @@ static const std::string s_FONT_SIZE_CONFIG = "fontSize"; ...@@ -46,6 +46,7 @@ static const std::string s_FONT_SIZE_CONFIG = "fontSize";
static const std::string s_FONT_SOURCE_CONFIG = "fontSource"; static const std::string s_FONT_SOURCE_CONFIG = "fontSource";
static const std::string s_ORIGIN_CONFIG = "origin"; static const std::string s_ORIGIN_CONFIG = "origin";
static const std::string s_ORIGIN_COLOR_CONFIG = "originColor"; static const std::string s_ORIGIN_COLOR_CONFIG = "originColor";
static const std::string s_AXIS_NAME = "name";
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
...@@ -80,6 +81,7 @@ void SAxis::configuring() ...@@ -80,6 +81,7 @@ void SAxis::configuring()
m_fontSize = config.get<size_t>(s_FONT_SIZE_CONFIG, m_fontSize); m_fontSize = config.get<size_t>(s_FONT_SIZE_CONFIG, m_fontSize);
m_fontSource = config.get(s_FONT_SOURCE_CONFIG, m_fontSource); m_fontSource = config.get(s_FONT_SOURCE_CONFIG, m_fontSource);
m_originVisibility = config.get<bool>(s_ORIGIN_CONFIG, m_originVisibility); m_originVisibility = config.get<bool>(s_ORIGIN_CONFIG, m_originVisibility);
m_axisName = config.get<std::string>(s_AXIS_NAME, m_axisName);
m_originColor = config.get<std::string>(s_ORIGIN_COLOR_CONFIG, m_originColor); m_originColor = config.get<std::string>(s_ORIGIN_COLOR_CONFIG, m_originColor);
SIGHT_ASSERT( SIGHT_ASSERT(
...@@ -98,11 +100,11 @@ void SAxis::starting() ...@@ -98,11 +100,11 @@ void SAxis::starting()
this->getRenderService()->makeCurrent(); this->getRenderService()->makeCurrent();
::Ogre::SceneNode* const rootSceneNode = this->getSceneManager()->getRootSceneNode(); Ogre::SceneNode* const rootSceneNode = this->getSceneManager()->getRootSceneNode();
::Ogre::SceneNode* const transformNode = this->getTransformNode(rootSceneNode); Ogre::SceneNode* const transformNode = this->getTransformNode(rootSceneNode);
m_sceneNode = transformNode->createChildSceneNode(this->getID() + "_mainNode"); m_sceneNode = transformNode->createChildSceneNode(this->getID() + "_mainNode");
::Ogre::SceneManager* const sceneMgr = this->getSceneManager(); Ogre::SceneManager* const sceneMgr = this->getSceneManager();
if(m_originVisibility) if(m_originVisibility)
{ {
...@@ -152,10 +154,11 @@ void SAxis::starting() ...@@ -152,10 +154,11 @@ void SAxis::starting()
{ {
const data::Color::sptr originColor = data::Color::New(); const data::Color::sptr originColor = data::Color::New();
originColor->setRGBA(m_originColor); originColor->setRGBA(m_originColor);
sight::viz::scene3d::helper::ManualObject::createSphere( sight::viz::scene3d::helper::ManualObject::createSphere(
m_origin, m_origin,
materialAdaptor->getMaterialName(), materialAdaptor->getMaterialName(),
::Ogre::ColourValue( Ogre::ColourValue(
originColor->red(), originColor->red(),
originColor->green(), originColor->green(),
originColor->blue(), originColor->blue(),
...@@ -164,6 +167,7 @@ void SAxis::starting() ...@@ -164,6 +167,7 @@ void SAxis::starting()
originRadius, originRadius,
sample sample
); );
m_sceneNode->attachObject(m_origin); m_sceneNode->attachObject(m_origin);
} }
...@@ -171,12 +175,12 @@ void SAxis::starting() ...@@ -171,12 +175,12 @@ void SAxis::starting()
sight::viz::scene3d::helper::ManualObject::createCylinder( sight::viz::scene3d::helper::ManualObject::createCylinder(
m_xLine, m_xLine,
materialAdaptor->getMaterialName(), materialAdaptor->getMaterialName(),
::Ogre::ColourValue(::Ogre::ColourValue::Red), Ogre::ColourValue(::Ogre::ColourValue::Red),
cylinderRadius, cylinderRadius,
cylinderLength, cylinderLength,
sample sample
); );
::Ogre::SceneNode* const xLineNode = m_sceneNode->createChildSceneNode(this->getID() + "_xLine"); Ogre::SceneNode* const xLineNode = m_sceneNode->createChildSceneNode(this->getID() + "_xLine");
xLineNode->attachObject(m_xLine); xLineNode->attachObject(m_xLine);
xLineNode->pitch(::Ogre::Degree(90)); xLineNode->pitch(::Ogre::Degree(90));
...@@ -184,12 +188,12 @@ void SAxis::starting() ...@@ -184,12 +188,12 @@ void SAxis::starting()
sight::viz::scene3d::helper::ManualObject::createCylinder( sight::viz::scene3d::helper::ManualObject::createCylinder(
m_yLine, m_yLine,
materialAdaptor->getMaterialName(), materialAdaptor->getMaterialName(),
::Ogre::ColourValue(::Ogre::ColourValue::Green), Ogre::ColourValue(::Ogre::ColourValue::Green),
cylinderRadius, cylinderRadius,
cylinderLength, cylinderLength,
sample sample
); );
::Ogre::SceneNode* const yLineNode = m_sceneNode->createChildSceneNode(this->getID() + "_yLine"); Ogre::SceneNode* const yLineNode = m_sceneNode->createChildSceneNode(this->getID() + "_yLine");
yLineNode->attachObject(m_yLine); yLineNode->attachObject(m_yLine);
yLineNode->roll(::Ogre::Degree(90)); yLineNode->roll(::Ogre::Degree(90));
...@@ -197,28 +201,28 @@ void SAxis::starting() ...@@ -197,28 +201,28 @@ void SAxis::starting()
sight::viz::scene3d::helper::ManualObject::createCylinder( sight::viz::scene3d::helper::ManualObject::createCylinder(
m_zLine, m_zLine,
materialAdaptor->getMaterialName(), materialAdaptor->getMaterialName(),
::Ogre::ColourValue(::Ogre::ColourValue::Blue), Ogre::ColourValue(::Ogre::ColourValue::Blue),
cylinderRadius, cylinderRadius,
cylinderLength, cylinderLength,
sample sample
); );
::Ogre::SceneNode* const zLineNode = m_sceneNode->createChildSceneNode(this->getID() + "_zLine"); Ogre::SceneNode* const zLineNode = m_sceneNode->createChildSceneNode(this->getID() + "_zLine");
zLineNode->attachObject(m_zLine); zLineNode->attachObject(m_zLine);
zLineNode->yaw(::Ogre::Degree(-90)); zLineNode->yaw(::Ogre::Degree(-90));
::Ogre::OverlayContainer* const textContainer = this->getLayer()->getOverlayTextPanel(); Ogre::OverlayContainer* const textContainer = this->getLayer()->getOverlayTextPanel();
::Ogre::Camera* const cam = this->getLayer()->getDefaultCamera(); Ogre::Camera* const cam = this->getLayer()->getDefaultCamera();
// X cone // X cone
sight::viz::scene3d::helper::ManualObject::createCone( sight::viz::scene3d::helper::ManualObject::createCone(
m_xCone, m_xCone,
materialAdaptor->getMaterialName(), materialAdaptor->getMaterialName(),
::Ogre::ColourValue(::Ogre::ColourValue::Red), Ogre::ColourValue(::Ogre::ColourValue::Red),
coneRadius, coneRadius,
coneLength, coneLength,
sample sample
); );
::Ogre::SceneNode* const xConeNode = m_sceneNode->createChildSceneNode(this->getID() + "_xCone"); Ogre::SceneNode* const xConeNode = m_sceneNode->createChildSceneNode(this->getID() + "_xCone");
if(m_enableLabel) if(m_enableLabel)
{ {
...@@ -242,12 +246,12 @@ void SAxis::starting() ...@@ -242,12 +246,12 @@ void SAxis::starting()
sight::viz::scene3d::helper::ManualObject::createCone( sight::viz::scene3d::helper::ManualObject::createCone(
m_yCone, m_yCone,
materialAdaptor->getMaterialName(), materialAdaptor->getMaterialName(),
::Ogre::ColourValue(::Ogre::ColourValue::Green), Ogre::ColourValue(::Ogre::ColourValue::Green),
coneRadius, coneRadius,
coneLength, coneLength,
sample sample
); );
::Ogre::SceneNode* const yConeNode = m_sceneNode->createChildSceneNode(this->getID() + "_yCone"); Ogre::SceneNode* const yConeNode = m_sceneNode->createChildSceneNode(this->getID() + "_yCone");
yConeNode->attachObject(m_yCone); yConeNode->attachObject(m_yCone);
if(m_enableLabel) if(m_enableLabel)
...@@ -272,12 +276,12 @@ void SAxis::starting() ...@@ -272,12 +276,12 @@ void SAxis::starting()
sight::viz::scene3d::helper::ManualObject::createCone( sight::viz::scene3d::helper::ManualObject::createCone(
m_zCone, m_zCone,
materialAdaptor->getMaterialName(), materialAdaptor->getMaterialName(),
::Ogre::ColourValue(::Ogre::ColourValue::Blue), Ogre::ColourValue(::Ogre::ColourValue::Blue),
coneRadius, coneRadius,
coneLength, coneLength,
sample sample
); );
::Ogre::SceneNode* const zConeNode = m_sceneNode->createChildSceneNode(this->getID() + "_zCone"); Ogre::SceneNode* const zConeNode = m_sceneNode->createChildSceneNode(this->getID() + "_zCone");
zConeNode->attachObject(m_zCone); zConeNode->attachObject(m_zCone);
if(m_enableLabel) if(m_enableLabel)
...@@ -298,6 +302,22 @@ void SAxis::starting() ...@@ -298,6 +302,22 @@ void SAxis::starting()
zConeNode->translate(0.f, 0.f, cylinderLength); zConeNode->translate(0.f, 0.f, cylinderLength);
zConeNode->yaw(::Ogre::Degree(-90)); zConeNode->yaw(::Ogre::Degree(-90));
// Display Name if provided.
if(!m_axisName.empty())
{
m_axisNameTxt = sight::viz::scene3d::Text::New(
this->getID() + "_Name",
sceneMgr,
textContainer,
m_fontSource,
m_fontSize,
dpi,
cam
);
m_axisNameTxt->setText(m_axisName);
m_sceneNode->attachObject(m_axisNameTxt);
}
this->updateVisibility(m_isVisible); this->updateVisibility(m_isVisible);
this->requestRender(); this->requestRender();
...@@ -316,7 +336,7 @@ void SAxis::stopping() ...@@ -316,7 +336,7 @@ void SAxis::stopping()
{ {
this->getRenderService()->makeCurrent(); this->getRenderService()->makeCurrent();
::Ogre::SceneManager* const sceneMgr = this->getSceneManager(); Ogre::SceneManager* const sceneMgr = this->getSceneManager();
if(m_sceneNode != nullptr) if(m_sceneNode != nullptr)
{ {
...@@ -339,6 +359,13 @@ void SAxis::stopping() ...@@ -339,6 +359,13 @@ void SAxis::stopping()
} }
} }
if(m_axisNameTxt)
{
m_axisNameTxt->detachFromParent();
sceneMgr->destroyMovableObject(m_axisNameTxt);
m_axisNameTxt = nullptr;
}
if(m_originVisibility) if(m_originVisibility)
{ {
sceneMgr->destroyManualObject(m_origin); sceneMgr->destroyManualObject(m_origin);
...@@ -352,8 +379,8 @@ void SAxis::stopping() ...@@ -352,8 +379,8 @@ void SAxis::stopping()
sceneMgr->destroyManualObject(m_yCone); sceneMgr->destroyManualObject(m_yCone);
sceneMgr->destroyManualObject(m_zCone); sceneMgr->destroyManualObject(m_zCone);
::Ogre::SceneNode* const rootSceneNode = sceneMgr->getRootSceneNode(); Ogre::SceneNode* const rootSceneNode = sceneMgr->getRootSceneNode();
::Ogre::SceneNode* const transformNode = this->getTransformNode(rootSceneNode); Ogre::SceneNode* const transformNode = this->getTransformNode(rootSceneNode);
transformNode->removeAndDestroyChild(this->getID() + "_mainNode"); transformNode->removeAndDestroyChild(this->getID() + "_mainNode");
this->unregisterServices(); this->unregisterServices();
...@@ -375,6 +402,11 @@ void SAxis::setVisible(bool _visible) ...@@ -375,6 +402,11 @@ void SAxis::setVisible(bool _visible)
label->setVisible(_visible); label->setVisible(_visible);
} }
} }
if(m_axisNameTxt)
{
m_axisNameTxt->setVisible(_visible);
}
} }
this->updating(); this->updating();
......
...@@ -55,7 +55,7 @@ namespace sight::module::viz::scene3d::adaptor ...@@ -55,7 +55,7 @@ namespace sight::module::viz::scene3d::adaptor
* @section XML XML Configuration * @section XML XML Configuration
* @code{.xml} * @code{.xml}
<service uid="..." type="sight::module::viz::scene3d::adaptor::SAxis"> <service uid="..." type="sight::module::viz::scene3d::adaptor::SAxis">
<config layer="default" transform="transformUID" length="30" label="true" /> <config layer="default" transform="transformUID" length="30" label="true" name="A1" />
</service> </service>
@endcode @endcode
* *
...@@ -69,6 +69,7 @@ namespace sight::module::viz::scene3d::adaptor ...@@ -69,6 +69,7 @@ namespace sight::module::viz::scene3d::adaptor
* - \b length (optional, float, default=50.f): axis length in scene units. * - \b length (optional, float, default=50.f): axis length in scene units.
* - \b label (optional, bool, default=true): display axis names. * - \b label (optional, bool, default=true): display axis names.
* - \b fontSize (optional, unsigned int, default=16): label font size in points. * - \b fontSize (optional, unsigned int, default=16): label font size in points.
* - \b name (optional, string): displayed name of the axis (default empty).
*/ */
class MODULE_VIZ_SCENE3D_CLASS_API SAxis final : class MODULE_VIZ_SCENE3D_CLASS_API SAxis final :
public sight::viz::scene3d::IAdaptor, public sight::viz::scene3d::IAdaptor,
...@@ -149,11 +150,16 @@ private: ...@@ -149,11 +150,16 @@ private:
/// Stores labels attached to each axis. /// Stores labels attached to each axis.
std::array<sight::viz::scene3d::Text*, 3> m_axisLabels {{nullptr, nullptr, nullptr}}; std::array<sight::viz::scene3d::Text*, 3> m_axisLabels {{nullptr, nullptr, nullptr}};
sight::viz::scene3d::Text* m_axisNameTxt {nullptr};
/// Defines labels font size in points. /// Defines labels font size in points.
size_t m_fontSize {16}; size_t m_fontSize {16};
/// Defines the TrueType font source file. /// Defines the TrueType font source file.
std::string m_fontSource {"DejaVuSans.ttf"}; std::string m_fontSource {"DejaVuSans.ttf"};
/// Axis name, default empty.
std::string m_axisName;
}; };
} // namespace sight::module::viz::scene3d::adaptor. } // namespace sight::module::viz::scene3d::adaptor.
...@@ -169,7 +169,7 @@ ...@@ -169,7 +169,7 @@
</service> </service>
<service uid="axis1Adp" type="sight::module::viz::scene3d::adaptor::SAxis" > <service uid="axis1Adp" type="sight::module::viz::scene3d::adaptor::SAxis" >
<config layer="default" length="10" transform="transRotMat" label="false" origin="true" originColor="#6997BB" /> <config layer="default" length="10" transform="transRotMat" label="false" origin="true" originColor="#6997BB" name="Base" />
</service> </service>
<service uid="axis2Adp" type="sight::module::viz::scene3d::adaptor::SAxis" > <service uid="axis2Adp" type="sight::module::viz::scene3d::adaptor::SAxis" >
...@@ -240,13 +240,17 @@ ...@@ -240,13 +240,17 @@
<slot>mesh2Adp/updateVisibility</slot> <slot>mesh2Adp/updateVisibility</slot>
</connect> </connect>
<connect>
<signal>trackballInteractorAdp/started</signal>
<slot>genericSceneSrv/resetCameras</slot>
</connect>
<!-- ******************************* Start services ***************************************** --> <!-- ******************************* Start services ***************************************** -->
<start uid="mainFrame" /> <start uid="mainFrame" />
<start uid="matrixDecomposerAdp" /> <start uid="matrixDecomposerAdp" />
<start uid="concatenateTranslationAndRotationArv" /> <start uid="concatenateTranslationAndRotationArv" />
<start uid="concatenateRotationAndTranslationSrv" /> <start uid="concatenateRotationAndTranslationSrv" />
<start uid="trackballInteractorAdp" />
<start uid="mesh1Adp" /> <start uid="mesh1Adp" />
<start uid="mesh2Adp" /> <start uid="mesh2Adp" />
<start uid="matrix1Adp" /> <start uid="matrix1Adp" />
...@@ -256,6 +260,7 @@ ...@@ -256,6 +260,7 @@
<start uid="originAxisAdp" /> <start uid="originAxisAdp" />
<start uid="text1Adp" /> <start uid="text1Adp" />
<start uid="text2Adp" /> <start uid="text2Adp" />
<start uid="trackballInteractorAdp" />
</config> </config>
</extension> </extension>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment