Skip to content

Commit

Permalink
Merge pull request #439 from albertoesmp/devel (swap-on-repeat)
Browse files Browse the repository at this point in the history
Initial swap-on-repeat with bugs fixed after testing.
  • Loading branch information
albertoesmp authored Apr 25, 2024
2 parents 9eda8c2 + 1aae876 commit 354ff8d
Show file tree
Hide file tree
Showing 10 changed files with 246 additions and 13 deletions.
167 changes: 167 additions & 0 deletions data/scenes/dyn/dyn_geom_swap_scene_by_indices.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
<?xml version="1.0" encoding="UTF-8"?>
<document>
<scene id="dyn_geom_swap_scene" name="DynGeomSwapScene">


<!-- 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>




<!-- Small cube goes sphere for two repetitions then goes big cube -->
<!-- ************************************************************* -->
<part id="2">
<filter type="objloader">
<param type="string" key="filepath" value="data/sceneparts/toyblocks/cube.obj" />
</filter>
<filter type="rotate">
<param key="rotation" type="rotation">
<rot angle_deg="45" axis="z"/>
</param>
</filter>
<filter type="scale">
<param type="double" key="scale" value="0.75" />
</filter>
<filter type="translate">
<param type="vec3" key="offset" value="-40.0;-50.0;0" />
</filter>
<!-- Swap sphere by big cube -->
<swap swapIndices="[3]">
<filter type="objloader">
<param type="string" key="filepath" value="data/sceneparts/toyblocks/cube.obj" />
</filter>
<filter type="rotate">
<param key="rotation" type="rotation">
<rot angle_deg="45" axis="z"/>
</param>
</filter>
<filter type="scale">
<param type="double" key="scale" value="1.5" />
</filter>
<filter type="translate">
<param type="vec3" key="offset" value="-20.0;-60.0;0" />
</filter>
</swap>
<!-- Swap small cube by sphere -->
<swap swapIndices="[1, 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.25" />
</filter>
<filter type="translate">
<param type="vec3" key="offset" value="-30.0;-60.0;0" />
</filter>
</swap>
</part>




<!-- Sphere goes cube goes nothing -->
<!-- ***************************** -->
<part id="3">
<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.25" />
</filter>
<filter type="translate">
<param type="vec3" key="offset" value="-10.0;-20.0;0" />
</filter>
<!-- Swap sphere by cube -->
<swap swapIndices="[1]">
<filter type="objloader">
<param type="string" key="filepath" value="data/sceneparts/toyblocks/cube.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>
<!-- Swap cube by nothing -->
<swap swapIndices="[2]" force_null="true">
</swap>
</part>




<!-- Small cube goes mid goes big goes bigger -->
<!-- **************************************** -->
<part id="4">
<filter type="objloader">
<param type="string" key="filepath" value="data/sceneparts/toyblocks/cube.obj" />
</filter>
<filter type="rotate">
<param key="rotation" type="rotation">
<rot angle_deg="45" axis="z"/>
</param>
</filter>
<filter type="scale">
<param type="double" key="scale" value="0.75" />
</filter>
<filter type="translate">
<param type="vec3" key="offset" value="-20.0;10.0;0" />
</filter>
<!-- Swap big cube by bigger cube -->
<swap swapIndices="[3]">
<filter type="rotate">
<param key="rotation" type="rotation">
<rot angle_deg="45" axis="z"/>
</param>
</filter>
<filter type="scale">
<param type="double" key="scale" value="3.5" />
</filter>
<filter type="translate">
<param type="vec3" key="offset" value="-42.0;12.0;0.0" />
</filter>
</swap>
<!-- Swap small cube by mid cube -->
<swap swapIndices="[1]">
<filter type="rotate">
<param key="rotation" type="rotation">
<rot angle_deg="45" axis="z"/>
</param>
</filter>
<filter type="scale">
<param type="double" key="scale" value="2.0" />
</filter>
<filter type="translate">
<param type="vec3" key="offset" value="-22.0;12.0;0" />
</filter>
</swap>
<!-- Swap mid cube by big cube -->
<swap swapIndices="[2]">
<filter type="rotate">
<param key="rotation" type="rotation">
<rot angle_deg="45" axis="z"/>
</param>
</filter>
<filter type="scale">
<param type="double" key="scale" value="3.0" />
</filter>
<filter type="translate">
<param type="vec3" key="offset" value="-18.0;11.0;0.0" />
</filter>
</swap>
</part>
</scene>
</document>
6 changes: 6 additions & 0 deletions src/assetloading/SpectralLibrary.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,10 @@ class SpectralLibrary {
* @param scene Scene with materials which reflectance must be setted
*/
void setReflectances(Scene* scene);

/**
* @brief Obtain the default reflectance of the spectral library.
* @see SpectralLibrary::defaultReflectance
*/
inline double getDefaultReflectance(){return defaultReflectance;}
};
3 changes: 3 additions & 0 deletions src/assetloading/XmlSurveyLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ XmlSurveyLoader::createSurveyFromXml(
(float)survey->scanner->getWavelength(), assetsDir + "spectra");
spectralLibrary.readReflectances();
spectralLibrary.setReflectances(survey->scanner->platform->scene.get());
survey->scanner->platform->scene->setDefaultReflectance(
spectralLibrary.getDefaultReflectance()
);

// Update materials for all swap on repeat handlers
for(std::shared_ptr<ScenePart> sp : survey->scanner->platform->scene->parts){
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 = "4aa844cd";
const char * HELIOS_GIT_HASH = "e8bf9ebe";

const char * getHeliosVersion(){
return HELIOS_VERSION;
Expand Down
4 changes: 1 addition & 3 deletions src/scanner/ScanningDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,10 +286,8 @@ void ScanningDevice::computeSubrays(
){
size_t const numSubrays = cached_subrayRotation.size();
for(size_t i = 0 ; i < numSubrays ; ++i) {
#if DATA_ANALYTICS >=2
bool subrayHit;
#endif
#if DATA_ANALYTICS >=2
bool subrayHit;
std::vector<double> subraySimRecord(
14, std::numeric_limits<double>::quiet_NaN()
);
Expand Down
2 changes: 1 addition & 1 deletion src/scene/Scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ bool Scene::finalizeLoading(bool const safe) {

// Store original bounding box (CRS coordinates):
this->bbox_crs = AABB::getForPrimitives(primitives);
glm::dvec3 diff = this->bbox_crs->getMin();
glm::dvec3 const diff = this->bbox_crs->getMin();
stringstream ss;
ss << "CRS bounding box (by vertices): " << this->bbox_crs->toString()
<< "\nShift: " << glm::to_string(diff)
Expand Down
36 changes: 36 additions & 0 deletions src/scene/Scene.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,17 @@ class Scene : public Asset {
* @see Scene::getIntersections
*/
std::shared_ptr<KDGroveRaycaster> raycaster;
/**
* @brief The default reflectance that must be used for primitives with
* not reflectance (NaN). It is typically loaded through the spectral
* library and then assigned to the scene so it can be known when needed.
* @see Scene::setDefaultReflectance
* @see Scene::getDefaultReflectance
* @see SpectralLibrary
* @see SpectralLibrary::defaultReflectance
* @see XmlSurveyLoader::createSurveyFromXml
*/
double defaultReflectance = 50.0;

public:
/**
Expand Down Expand Up @@ -473,6 +484,31 @@ class Scene : public Asset {
* @see ScenePart::sorh
*/
std::vector<std::shared_ptr<ScenePart>> getSwapOnRepeatObjects();
/**
* @brief Set the default reflectance that must be used for primitives
* that have no assigned reflectance.
* @param defaultReflectance The new default reflectance.
* @see Scene::defaultReflectance
* @see Scene::getDefaultReflectance
* @see SpectralLibrary
* @see SpectralLibrary::defaultReflectance
* @see XmlSurveyLoader::createSurveyFromXml
*/
inline void setDefaultReflectance(double const defaultReflectance)
{this->defaultReflectance = defaultReflectance;}
/**
* @brief Get the default reflectance that must be used for primitives that
* have not got an assigned reflectance.
* @return The default reflectance for primitives that have not got an
* assigned reflectance.
* @see Scene::setDefaultReflectance
* @see SpectralLibrary
* @see SpectralLibrary::defaultReflectance
* @see XmlSurveyLoader::createSurveyFromXml
*/
inline double getDefaultReflectance() const {return defaultReflectance;}



// *** READ/WRITE *** //
// ********************* //
Expand Down
15 changes: 11 additions & 4 deletions src/sim/comps/SimulationPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ void SimulationPlayer::endPlay(){
// Restart scanner
logging::DEBUG("Restarting scanner for next simulation play ...");
restartScanner(*sim.getScanner());
// Restar scene
// Restart scene
logging::DEBUG("Restarting scene for next simulation play ...");
restartScene(*sim.getScanner()->platform->scene);
// Restart simulation
Expand Down Expand Up @@ -168,7 +168,7 @@ void SimulationPlayer::restartScene(Scene &scene){
if(sp->sorh != nullptr && sp->sorh->needsDiscardOnReplay()){
for(Primitive * p: sp->sorh->getBaselinePrimitives()) delete p;
for(Primitive * p: sp->mPrimitives) delete p;
sp->sorh = nullptr;
//sp->sorh = nullptr; // TODO Rethink : Remove to enable rebirth?
continue;
}
// Handle scene parts that must be preserved
Expand All @@ -181,7 +181,7 @@ void SimulationPlayer::restartScene(Scene &scene){
for(size_t i = 0 ; i < p->getNumVertices() ; ++i){
v[i].pos = v[i].pos + diff;
}
p->update();
//p->update(); // TODO Rethink : Avoid calling twice
}
}
// Handle scene parts who are in the first play after a swap
Expand All @@ -199,8 +199,15 @@ void SimulationPlayer::restartScene(Scene &scene){
}
scene.parts = newParts;
scene.primitives = newPrims;
// Apply default reflectances when needed
for(Primitive * p : scene.primitives){
Material &mat = *p->material;
if(std::isnan(mat.reflectance)){
mat.reflectance = scene.getDefaultReflectance();
}
}
// Reload scene
scene.finalizeLoading(false);
scene.finalizeLoading(false); // TODO Rethink : p->update is called here
}

void SimulationPlayer::restartSimulation(Simulation &sim){
Expand Down
17 changes: 14 additions & 3 deletions src/sim/core/Simulation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ using namespace std::chrono;
#include <platform/InterpolatedMovingPlatform.h>
#include <scene/dynamic/DynScene.h>
#ifdef DATA_ANALYTICS
#include <dataanalytics/HDA_StateJSONReporter.h>
#include <dataanalytics/HDA_SimStepRecorder.h>
using helios::analytics::HDA_StateJSONReporter;
using helios::analytics::HDA_SimStepRecorder;
using helios::analytics::HDA_Recorder;
#endif

#include "Simulation.h"
Expand Down Expand Up @@ -149,7 +149,11 @@ void Simulation::start() {
ss.str("");
ss << "Starting simulation loop " << simLoopIndex+1 << " ...";
logging::INFO(ss.str());
doSimLoop();
doSimLoop(
#ifdef DATA_ANALYTICS
ssr
#endif
);
// NOTE there is no need for a sync. barrier after the last iteration
// because end of simulation will handle it.
ss.str("");
Expand Down Expand Up @@ -191,7 +195,14 @@ void Simulation::start() {
shutdown();
}

void Simulation::doSimLoop(){
void Simulation::doSimLoop(
#ifdef DATA_ANALYTICS
HDA_Recorder &_ssr
#endif
){
#ifdef DATA_ANALYTICS
HDA_SimStepRecorder &ssr = static_cast<HDA_SimStepRecorder &>(_ssr);
#endif
size_t iter = 1;
// Execute the main loop of the simulation
while (!isStopped()) {
Expand Down
7 changes: 6 additions & 1 deletion src/sim/core/Simulation.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#endif
#ifdef DATA_ANALYTICS
#include <dataanalytics/HDA_StateJSONReporter.h>
#include <dataanalytics/HDA_Recorder.h>
#endif
#include <SimulationReporter.h>
#include <SimulationPlayer.h>
Expand Down Expand Up @@ -219,7 +220,11 @@ class Simulation {
* the computations between the first and the last leg of the survey.
* @return The number of iterations run in the simulation loop.
*/
virtual void doSimLoop();
virtual void doSimLoop(
#ifdef DATA_ANALYTICS
helios::analytics::HDA_Recorder &ssr
#endif
);
/**
* @brief Stop the simulation
*
Expand Down

0 comments on commit 354ff8d

Please sign in to comment.