Skip to content

Commit

Permalink
Merge pull request #460 from 3dgeo-heidelberg/devel-aux
Browse files Browse the repository at this point in the history
Swap-on-repeat supports recycling
  • Loading branch information
han16nah authored Jun 12, 2024
2 parents 1fff9a6 + 58d503f commit 4bbef0b
Show file tree
Hide file tree
Showing 8 changed files with 161 additions and 6 deletions.
76 changes: 76 additions & 0 deletions data/scenes/dyn/dyn_geom_swap_recycle_scene.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?xml version="1.0" encoding="UTF-8"?>
<document>
<scene id="dyn_geom_swap_recycle_scene" name="DynGeomSwapRecycleScene">


<!-- Ground plane -->
<!-- ************ -->
<part id="1">
<filter type="objloader">
<param type="string" key="filepath" value="data/sceneparts/basic/groundplane/groundplane.obj" />
</filter>
<filter type="scale">
<param type="double" key="scale" value="120" />
</filter>
<filter type="translate">
<param type="vec3" key="offset" value="50.0;0;0" />
</filter>
</part>




<!-- Sphere goes big sphere goes nothing goes big sphere -->
<!-- *************************************************** -->
<part id="2">
<filter type="objloader">
<param type="string" key="filepath" value="data/sceneparts/toyblocks/sphere.obj" />
</filter>
<filter type="scale">
<param type="double" key="scale" value="1.0" />
</filter>
<filter type="translate">
<param type="vec3" key="offset" value="-10.0;-20.0;0" />
</filter>
<!-- Swap sphere by big sphere -->
<swap>
<filter type="scale">
<param type="double" key="scale" value="1.5" />
</filter>
<filter type="translate">
<param type="vec3" key="offset" value="-10.0;-20.0;0" />
</filter>
</swap>
<!-- Swap big sphere by nothing -->
<swap force_null="true" swapStep="2">
</swap>
<!-- Swap nothing by big sphere -->
<swap>
<filter type="objloader">
<param type="string" key="filepath" value="data/sceneparts/toyblocks/sphere.obj" />
</filter>
<filter type="scale">
<param type="double" key="scale" value="1.5" />
</filter>
<filter type="translate">
<param type="vec3" key="offset" value="-10.0;-20.0;0" />
</filter>
</swap>
<!-- Swap big sphere by nothing -->
<swap force_null="true" swapStep="1">
</swap>
<!-- Swap nothing by biggest sphere -->
<swap>
<filter type="objloader">
<param type="string" key="filepath" value="data/sceneparts/toyblocks/sphere.obj" />
</filter>
<filter type="scale">
<param type="double" key="scale" value="2.0" />
</filter>
<filter type="translate">
<param type="vec3" key="offset" value="-40.0;-40.0;0" />
</filter>
</swap>
</part>
</scene>
</document>
21 changes: 21 additions & 0 deletions data/surveys/dyn/als_dyn_geom_swap_recycle.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<document>
<survey name="dyn_geom_swap_recycle_als" scene="data/scenes/dyn/dyn_geom_swap_recycle_scene.xml#dyn_geom_swap_recycle_scene" platform="data/platforms.xml#sr22" scanner="data/scanners_als.xml#leica_als50">
<leg>
<platformSettings x="100" y="100.0" z="400" onGround="false" movePerSec_m="5" />
<scannerSettings active="true" pulseFreq_hz="83000" scanFreq_hz="70" scanAngle_deg="60" />
</leg>
<leg>
<platformSettings x="-100" y="-100.0" z="400" onGround="false" movePerSec_m="5" />
<scannerSettings active="false" pulseFreq_hz="83000" scanFreq_hz="70" scanAngle_deg="60" />
</leg>
<leg>
<platformSettings x="-100" y="100.0" z="400" onGround="false" movePerSec_m="5" />
<scannerSettings active="true" pulseFreq_hz="83000" scanFreq_hz="70" scanAngle_deg="60" />
</leg>
<leg>
<platformSettings x="100" y="-100.0" z="400" onGround="false" movePerSec_m="5" />
<scannerSettings active="false" pulseFreq_hz="83000" scanFreq_hz="70" scanAngle_deg="60" />
</leg>
</survey>
</document>
13 changes: 12 additions & 1 deletion src/assetloading/ScenePart.h
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ class ScenePart {
*/
virtual void release();

// *** GETTERS and SETTERS *** //
// *** GETTERS and SETTERS *** //
// ***************************** //
/**
* @brief Obtain the primitives of the scene part
Expand Down Expand Up @@ -340,6 +340,17 @@ class ScenePart {
inline std::shared_ptr<SwapOnRepeatHandler> getSwapOnRepeatHandler()
{return sorh;}

/**
* @brief Check whether the scene part is null, according to the underlying
* swap on repeat handler.
* @return True if the scene part is null, false otherwise.
* @see SwapOnRepeatHandler
* @see SwapOnRepeatHandler::null
* @see SwapOnRepeatHandler::isNull
*/
inline bool isNull() const
{return (sorh==nullptr) ? false : sorh->isNull();}

// *** STATIC METHODS *** //
// ************************ //
/**
Expand Down
3 changes: 2 additions & 1 deletion src/assetloading/SwapOnRepeatHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ SwapOnRepeatHandler::SwapOnRepeatHandler() :
holistic(false),
onSwapFirstPlay(false),
keepCRS(true),
baseline(nullptr)
baseline(nullptr),
null(false)
{}


Expand Down
33 changes: 32 additions & 1 deletion src/assetloading/SwapOnRepeatHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ class SwapOnRepeatHandler {
* bounding box (default), False otherwise.
*/
bool keepCRS;
/**
* @brief Whether the handled scene part is null (e.g., it has been
* discarded). It can be useful to handle null scene parts that will
* be recycled in the future (they are flagged as null instead of
* fully deleted, so they can become available later on).
*/
bool null;

public:
/**
Expand Down Expand Up @@ -158,6 +165,18 @@ class SwapOnRepeatHandler {
*/
inline void setDiscardOnReplay(bool const discardOnReplay)
{this->discardOnReplay = discardOnReplay;}
/**
* @brief Check whether there are pending filters (True) or not (False).
*
* A SwapOnRepeatHandler is said to have no future if there are no further
* filters to be applied at any point in the future. When the handler
* needs to be discarded on replay and it has no future, it can be fully
* deleted. Otherwise, it will be recycled in the future despite it is
* discarded in the present.
*
* @see SwapOnRepeatHandler::swapFilters
*/
inline bool hasNoFuture() const {return swapFilters.empty();}
/**
* @brief Push the swap filters to the handler.
*
Expand Down Expand Up @@ -191,12 +210,24 @@ class SwapOnRepeatHandler {
*/
inline void setKeepCRS(bool const keepCRS) {this->keepCRS = keepCRS;}
/**
* @brief Check whether the current keepCRS flag.
* @brief Check whether the current keepCRS flag is enabled.
* @return True if the handler requires to keep the current scene's CRS,
* False otherwise.
* @see SwapOnRepeatHandler::keepCRS
*/
inline bool isKeepCRS() const {return keepCRS;}
/**
* @brief Check whether the current null flag is enabled.
* @return True if the handled scene part is null, False otherwise.
* @see SwapOnRepeatHandler::null
*/
inline bool isNull() const {return null;}
/**
* @brief Set the null flag.
* @param null The new null flag for the handler.
* @see SwapOnRepeatHandler::null
*/
inline void setNull(bool const null) {this->null = null;}

protected:
// *** UTIL METHODS *** //
Expand Down
2 changes: 1 addition & 1 deletion src/main/helios_version.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

const char * HELIOS_VERSION = "1.3.0";

const char * HELIOS_GIT_HASH = "99f2973f";
const char * HELIOS_GIT_HASH = "0dd016f8";

const char * getHeliosVersion(){
return HELIOS_VERSION;
Expand Down
1 change: 1 addition & 0 deletions src/scene/Scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ void Scene::doForceOnGround(){
size_t const m = parts.size(); // How many parts there are in the scene
for(size_t i=0 ; i < m ; ++i){
shared_ptr<ScenePart> part = parts[i];
if(part->isNull()) continue;
if(!part->mPrimitives[0]->material->isGround) continue;
I.push_back(i); // Store index of found ground part
planes.push_back(nullptr); // Null placeholder for best fitting plane
Expand Down
18 changes: 16 additions & 2 deletions src/sim/comps/SimulationPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,20 @@ void SimulationPlayer::restartScene(Scene &scene, bool const keepCRS){
AABB const oldCRSBBox = *scene.getBBoxCRS();
for(std::shared_ptr<ScenePart> sp : scene.parts){
// Handle scene parts that need to be discarded
if(sp->sorh != nullptr && sp->sorh->needsDiscardOnReplay()){
if(
sp->sorh != nullptr &&
sp->sorh->needsDiscardOnReplay() &&
!sp->isNull()
){
for(Primitive * p: sp->sorh->getBaselinePrimitives()) delete p;
for(Primitive * p: sp->mPrimitives) delete p;
//sp->sorh = nullptr; // TODO Rethink : Remove to enable rebirth?
if(sp->sorh->hasNoFuture()) sp->sorh = nullptr;
else {
sp->sorh->setNull(true);
sp->sorh->getBaselinePrimitives().clear();
sp->mPrimitives.clear();
newParts.push_back(sp);
}
continue;
}
// Handle scene parts that must be preserved
Expand All @@ -189,6 +199,10 @@ void SimulationPlayer::restartScene(Scene &scene, bool const keepCRS){
if(sp->sorh != nullptr && sp->sorh->isOnSwapFirstPlay()) {
ScenePart::computeTransformations(sp, sp->sorh->isHolistic());
sp->sorh->setOnSwapFirstPlay(false);
if(!sp->mPrimitives.empty()) {
sp->sorh->setNull(false);
sp->sorh->setDiscardOnReplay(false);
}
}
// Prepare new data for scene
newParts.push_back(sp);
Expand Down

0 comments on commit 4bbef0b

Please sign in to comment.