Skip to content

Commit

Permalink
Untested WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Robadob committed Oct 18, 2024
1 parent ed7d1d7 commit 4b19fc4
Show file tree
Hide file tree
Showing 10 changed files with 369 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,18 @@
#include "flamegpu/simulation/detail/CUDAErrorChecking.cuh"
#include "flamegpu/detail/type_decode.h"
#include "flamegpu/util/StringPair.h"

namespace flamegpu {
#ifdef FLAMEGPU_VISUALISATION
namespace visualiser {
struct ModelVisData;
}
#endif
namespace detail {
class CUDAScatter;
namespace curve {
class HostCurve;
class CurveRTCHost;
}

/**
* This represents the equivalent of CUDAAgent, CUDAMessage for EnvironmentDirectedGraph
* As the graph cannot be modified on the device, the host buffers can be assumed to always holds the truth
Expand Down Expand Up @@ -66,6 +69,12 @@ class CUDAEnvironmentDirectedGraphBuffers {
std::map<std::string, Buffer> edge_buffers;
std::list<std::weak_ptr<detail::curve::HostCurve>> curve_instances;
std::list<std::weak_ptr<detail::curve::CurveRTCHost>> rtc_curve_instances;
#ifdef FLAMEGPU_VISUALISATION
/**
* Empty if getVisualisation() hasn't been called
*/
mutable std::weak_ptr<visualiser::ModelVisData> visualisation;
#endif
size_type vertex_count;
size_type edge_count;
bool requires_rebuild;
Expand Down Expand Up @@ -267,6 +276,11 @@ class CUDAEnvironmentDirectedGraphBuffers {
* @throws exception::InvalidID If the ID is not in use
*/
unsigned int getEdgeIndex(id_t src_vertex_id, id_t dest_vertex_id) const;
#ifdef FLAMEGPU_VISUALISATION
void setVisualisation(std::shared_ptr<visualiser::ModelVisData> &_visualisation) const {
this->visualisation = _visualisation;
}
#endif
};


Expand Down
71 changes: 71 additions & 0 deletions include/flamegpu/visualiser/EnvironmentGraphVis.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#ifndef INCLUDE_FLAMEGPU_VISUALISER_ENVIRONMENTGRAPHVIS_H_
#define INCLUDE_FLAMEGPU_VISUALISER_ENVIRONMENTGRAPHVIS_H_
#ifdef FLAMEGPU_VISUALISATION

#include <memory>
#include <string>

#include "flamegpu/visualiser/color/Color.h"

namespace flamegpu {
struct EnvironmentDirectedGraphData;
namespace detail {
class CUDAEnvironmentDirectedGraphBuffers;
} // namespace detail
namespace visualiser {
struct LineConfig;

struct EnvironmentGraphVisData {
explicit EnvironmentGraphVisData(std::shared_ptr<detail::CUDAEnvironmentDirectedGraphBuffers> _graph, std::shared_ptr<LineConfig>_lines);
void constructGraph();
std::string x_varName = "x";
std::string y_varName = "y";
std::string z_varName = "z";
std::string xy_varName;
std::string xyz_varName;
Color color;
const EnvironmentDirectedGraphData &graphData;
const std::shared_ptr<const detail::CUDAEnvironmentDirectedGraphBuffers> graph;
const std::shared_ptr<LineConfig> lines;
};
class EnvironmentGraphVis {
public:
explicit EnvironmentGraphVis(std::shared_ptr<EnvironmentGraphVisData> data);

/**
* Set the name of the variable representing the agents x/y/z location coordinates
* @param var_name Name of the agent variable
* @note unnecessary if the variables are named "x", "y", "z" respectively
* @note Implicitly calls clearXYProperty(), clearXYZProperty()
* @throws InvalidEnvProperty If the variable is not type float[1]
*/
void setXProperty(const std::string &var_name);
void setYProperty(const std::string &var_name);
void setZProperty(const std::string &var_name);
/**
* Set the name of the array variable (length 2) representing the agents x/y location coordinates
* @param var_name Name of the agent variable
* @note Implicitly calls clearXProperty(), clearYProperty(), clearZProperty(),clearXYZProperty()
* @throws InvalidEnvProperty If the variable is not type float[2]
*/
void setXYProperty(const std::string &var_name);
/**
* Set the name of the array variable (length 3) representing the agents x/y/z location coordinates
* @param var_name Name of the agent variable
* @note Implicitly calls clearXProperty(), clearYProperty(), clearZProperty(),clearXYProperty()
* @throws InvalidEnvProperty If the variable is not type float[3]
*/
void setXYZProperty(const std::string &var_name);

void setColor(const Color& cf);
private:
/**
* Pointer to data struct
*/
std::shared_ptr<EnvironmentGraphVisData> data;
};
} // namespace visualiser
} // namespace flamegpu

#endif // FLAMEGPU_VISUALISATION
#endif // INCLUDE_FLAMEGPU_VISUALISER_ENVIRONMENTGRAPHVIS_H_
4 changes: 4 additions & 0 deletions include/flamegpu/visualiser/LineVis.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ class LineVis {
* @note Y is considered the vertical axis
*/
void addVertex(float x, float y, float z = 0.0f);
/**
* Remove all sketch data to start drawing a replacement
*/
void clear();

private:
/**
Expand Down
29 changes: 29 additions & 0 deletions include/flamegpu/visualiser/ModelVis.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

// @todo - All vis headers should live in the vis repo.
#include "flamegpu/visualiser/AgentVis.h"
#include "flamegpu/visualiser/EnvironmentGraphVis.h"
#include "flamegpu/visualiser/StaticModelVis.h"
#include "flamegpu/visualiser/LineVis.h"
#include "flamegpu/visualiser/PanelVis.h"
Expand All @@ -33,6 +34,11 @@ struct ModelVisData {
* > On resize, also update textures
*/
explicit ModelVisData(const CUDASimulation& model/*TBD*/);
/**
* Pass the vis shared pointer to directed graphs so they can trigger updates
* @param vis pointer to this
*/
void hookVis(std::shared_ptr<visualiser::ModelVisData> &vis);
/**
* Main struct of visualisation configuration options for the model
*/
Expand All @@ -46,6 +52,10 @@ struct ModelVisData {
* Per agent, visualisation configuration options
*/
std::unordered_map<std::string, std::shared_ptr<AgentVisData>> agents;
/**
* Per environment direct graph, visualisation configuration options
*/
std::unordered_map<std::string, std::shared_ptr<EnvironmentGraphVisData>> graphs;
/**
* Reference back to the model to be visualised
*/
Expand Down Expand Up @@ -75,6 +85,14 @@ struct ModelVisData {
* Random seed has changed
*/
void updateRandomSeed();
/**
* Rebuild all environment graph sketches
*/
void buildEnvGraphs();
/**
* Rebuild a specific environment graph sketch
*/
void rebuildEnvGraph(const std::string& graph_name);
};

/**
Expand Down Expand Up @@ -110,6 +128,17 @@ class ModelVis {
* @see addAgent(const std::string&)
*/
AgentVis Agent(const std::string &agent_name);
/**
* Select a graph to be rendered
* @param graph_name The name of the environment directed graph to visualise
* @return A handle to configure the visualisation of the specified graph
*/
EnvironmentGraphVis addGraph(const std::string &graph_name);
/**
* Returns the configuration handler if the environment directed graph has been marked for visualisation
* @see addGraph(const std::string&)
*/
EnvironmentGraphVis Graph(const std::string& graph_name);
/**
* Set the title for the visualisation window
* This value defaults to the model's name
Expand Down
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@ SET(SRC_INCLUDE_VISUALISER
${FLAMEGPU_ROOT}/include/flamegpu/visualiser/ModelVis.h
${FLAMEGPU_ROOT}/include/flamegpu/visualiser/AgentVis.h
${FLAMEGPU_ROOT}/include/flamegpu/visualiser/AgentStateVis.h
${FLAMEGPU_ROOT}/include/flamegpu/visualiser/EnvironmentGraphVis.h
${FLAMEGPU_ROOT}/include/flamegpu/visualiser/StaticModelVis.h
${FLAMEGPU_ROOT}/include/flamegpu/visualiser/LineVis.h
${FLAMEGPU_ROOT}/include/flamegpu/visualiser/PanelVis.h
Expand All @@ -411,6 +412,7 @@ set(SRC_FLAMEGPU_VISUALISER
${FLAMEGPU_ROOT}/src/flamegpu/visualiser/ModelVis.cpp
${FLAMEGPU_ROOT}/src/flamegpu/visualiser/AgentVis.cpp
${FLAMEGPU_ROOT}/src/flamegpu/visualiser/AgentStateVis.cpp
${FLAMEGPU_ROOT}/src/flamegpu/visualiser/EnvironmentGraphVis.cpp
${FLAMEGPU_ROOT}/src/flamegpu/visualiser/StaticModelVis.cpp
${FLAMEGPU_ROOT}/src/flamegpu/visualiser/LineVis.cpp
${FLAMEGPU_ROOT}/src/flamegpu/visualiser/PanelVis.cpp
Expand Down
4 changes: 3 additions & 1 deletion src/flamegpu/simulation/CUDASimulation.cu
Original file line number Diff line number Diff line change
Expand Up @@ -1709,8 +1709,10 @@ const CUDASimulation::Config &CUDASimulation::getCUDAConfig() const {
}
#ifdef FLAMEGPU_VISUALISATION
visualiser::ModelVis CUDASimulation::getVisualisation() {
if (!visualisation)
if (!visualisation) {
visualisation = std::make_shared<visualiser::ModelVisData>(*this);
visualisation->hookVis(visualisation);
}
return visualiser::ModelVis(visualisation, isSWIG);
}
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
#include "flamegpu/simulation/detail/CUDAScatter.cuh"
#include "flamegpu/runtime/detail/curve/HostCurve.cuh"
#include "flamegpu/detail/cuda.cuh"
#ifdef FLAMEGPU_VISUALISATION
#include "flamegpu/visualiser/ModelVis.h"
#endif
#ifdef _MSC_VER
#pragma warning(push, 1)
#pragma warning(disable : 4706 4834)
Expand All @@ -18,6 +21,8 @@
#endif // __NVCC_DIAG_PRAGMA_SUPPORT__
#include <cub/cub.cuh>

#include "flamegpu/visualiser/FLAMEGPU_Visualisation.h"

Check failure on line 24 in src/flamegpu/simulation/detail/CUDAEnvironmentDirectedGraphBuffers.cu

View workflow job for this annotation

GitHub Actions / build (11.0, 3.12, OFF, Release, ubuntu-20.04)

flamegpu/visualiser/FLAMEGPU_Visualisation.h: No such file or directory

Check failure on line 24 in src/flamegpu/simulation/detail/CUDAEnvironmentDirectedGraphBuffers.cu

View workflow job for this annotation

GitHub Actions / build (12.0, 3.12, OFF, Release, ubuntu-20.04)

flamegpu/visualiser/FLAMEGPU_Visualisation.h: No such file or directory

Check failure on line 24 in src/flamegpu/simulation/detail/CUDAEnvironmentDirectedGraphBuffers.cu

View workflow job for this annotation

GitHub Actions / build (12.0, 3.12, OFF, Release, ubuntu-20.04)

flamegpu/visualiser/FLAMEGPU_Visualisation.h: No such file or directory

Check failure on line 24 in src/flamegpu/simulation/detail/CUDAEnvironmentDirectedGraphBuffers.cu

View workflow job for this annotation

GitHub Actions / build (11.2, 3.12, OFF, Release, ubuntu-20.04)

flamegpu/visualiser/FLAMEGPU_Visualisation.h: No such file or directory

Check failure on line 24 in src/flamegpu/simulation/detail/CUDAEnvironmentDirectedGraphBuffers.cu

View workflow job for this annotation

GitHub Actions / build (11.2, 3.12, OFF, Release, ubuntu-20.04)

flamegpu/visualiser/FLAMEGPU_Visualisation.h: No such file or directory

Check failure on line 24 in src/flamegpu/simulation/detail/CUDAEnvironmentDirectedGraphBuffers.cu

View workflow job for this annotation

GitHub Actions / build (11.8, 3.12, OFF, Release, ubuntu-22.04)

flamegpu/visualiser/FLAMEGPU_Visualisation.h: No such file or directory

Check failure on line 24 in src/flamegpu/simulation/detail/CUDAEnvironmentDirectedGraphBuffers.cu

View workflow job for this annotation

GitHub Actions / build (11.8, 3.12, OFF, Release, ubuntu-22.04)

flamegpu/visualiser/FLAMEGPU_Visualisation.h: No such file or directory

Check failure on line 24 in src/flamegpu/simulation/detail/CUDAEnvironmentDirectedGraphBuffers.cu

View workflow job for this annotation

GitHub Actions / build (12.0, 3.12, OFF, Release, ubuntu-22.04)

flamegpu/visualiser/FLAMEGPU_Visualisation.h: No such file or directory

Check failure on line 24 in src/flamegpu/simulation/detail/CUDAEnvironmentDirectedGraphBuffers.cu

View workflow job for this annotation

GitHub Actions / build (12.0, 3.12, OFF, Release, ubuntu-22.04)

flamegpu/visualiser/FLAMEGPU_Visualisation.h: No such file or directory

Check failure on line 24 in src/flamegpu/simulation/detail/CUDAEnvironmentDirectedGraphBuffers.cu

View workflow job for this annotation

GitHub Actions / build (12.6, 3.12, OFF, Beltsoff, ubuntu-22.04)

flamegpu/visualiser/FLAMEGPU_Visualisation.h: No such file or directory

Check failure on line 24 in src/flamegpu/simulation/detail/CUDAEnvironmentDirectedGraphBuffers.cu

View workflow job for this annotation

GitHub Actions / build (12.6, 3.12, OFF, Beltsoff, ubuntu-22.04)

flamegpu/visualiser/FLAMEGPU_Visualisation.h: No such file or directory

Check failure on line 24 in src/flamegpu/simulation/detail/CUDAEnvironmentDirectedGraphBuffers.cu

View workflow job for this annotation

GitHub Actions / build (12.6, 3.12, OFF, Release, ubuntu-22.04)

flamegpu/visualiser/FLAMEGPU_Visualisation.h: No such file or directory

Check failure on line 24 in src/flamegpu/simulation/detail/CUDAEnvironmentDirectedGraphBuffers.cu

View workflow job for this annotation

GitHub Actions / build (12.6, 3.12, OFF, Release, ubuntu-22.04)

flamegpu/visualiser/FLAMEGPU_Visualisation.h: No such file or directory

#ifdef __NVCC_DIAG_PRAGMA_SUPPORT__
#pragma nv_diag_default 1719
#else
Expand Down Expand Up @@ -570,6 +575,13 @@ void CUDAEnvironmentDirectedGraphBuffers::syncDevice_async(detail::CUDAScatter&
h_edge_index_map.emplace(std::pair{static_cast<id_t*>(e_srcdest_b.h_ptr)[i * 2 + 1], static_cast<id_t*>(e_srcdest_b.h_ptr)[i * 2 + 0]}, i);
}
}

#ifdef FLAMEGPU_VISUALISATION
if (auto vis = visualisation.lock()) {
vis->rebuildEnvGraph(graph_description.name);
vis->visualiser->updateDynamicLine(std::string("graph_") + graph_description.name);

Check failure on line 582 in src/flamegpu/simulation/detail/CUDAEnvironmentDirectedGraphBuffers.cu

View workflow job for this annotation

GitHub Actions / build (11.8, 3.12, ON, Release, ubuntu-22.04)

class "flamegpu::visualiser::FLAMEGPU_Visualisation" has no member "updateDynamicLine"

Check failure on line 582 in src/flamegpu/simulation/detail/CUDAEnvironmentDirectedGraphBuffers.cu

View workflow job for this annotation

GitHub Actions / build (11.2, 3.12, ON, Release, ubuntu-20.04)

class "flamegpu::visualiser::FLAMEGPU_Visualisation" has no member "updateDynamicLine"

Check failure on line 582 in src/flamegpu/simulation/detail/CUDAEnvironmentDirectedGraphBuffers.cu

View workflow job for this annotation

GitHub Actions / build (12.0, 3.12, ON, Release, ubuntu-20.04)

class "flamegpu::visualiser::FLAMEGPU_Visualisation" has no member "updateDynamicLine"

Check failure on line 582 in src/flamegpu/simulation/detail/CUDAEnvironmentDirectedGraphBuffers.cu

View workflow job for this annotation

GitHub Actions / build (12.6, 3.12, ON, Release, ubuntu-22.04)

class "flamegpu::visualiser::FLAMEGPU_Visualisation" has no member "updateDynamicLine"

Check failure on line 582 in src/flamegpu/simulation/detail/CUDAEnvironmentDirectedGraphBuffers.cu

View workflow job for this annotation

GitHub Actions / build (12.6.0, 3.12, ON, Release, windows-2022)

class "flamegpu::visualiser::FLAMEGPU_Visualisation" has no member "updateDynamicLine" [D:\a\FLAMEGPU2\FLAMEGPU2\build\FLAMEGPU\flamegpu.vcxproj]

Check failure on line 582 in src/flamegpu/simulation/detail/CUDAEnvironmentDirectedGraphBuffers.cu

View workflow job for this annotation

GitHub Actions / build (11.8.0, 3.12, ON, Release, windows-2019)

class "flamegpu::visualiser::FLAMEGPU_Visualisation" has no member "updateDynamicLine" [D:\a\FLAMEGPU2\FLAMEGPU2\build\FLAMEGPU\flamegpu.vcxproj]
}
#endif
requires_rebuild = false;
}
}
Expand Down
Loading

0 comments on commit 4b19fc4

Please sign in to comment.