Skip to content

Commit

Permalink
[dataflow] accelerate compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
MathiasPaulin committed Oct 5, 2022
1 parent fc632f5 commit 684d411
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 42 deletions.
34 changes: 32 additions & 2 deletions src/Dataflow/Core/EditableParameter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,22 @@ namespace Ra {
namespace Dataflow {
namespace Core {

/// \brief Basic introspection for Node internal data edition
/// This base class gives key information to associate editing capabilities (and gui) to
/// an node internal data.
///
struct RA_DATAFLOW_API EditableParameterBase {
/// \name Constructors
/// @{
/// \brief delete default constructors.
EditableParameterBase() = delete;
EditableParameterBase( const EditableParameterBase& ) = delete;
EditableParameterBase& operator=( const EditableParameterBase& ) = delete;

/// Construct an base editable parameter from its name and type hash
EditableParameterBase( std::string& name, size_t hashedType );
///@}

virtual ~EditableParameterBase() = default;
std::string getName();
std::string m_name { "" };
Expand All @@ -19,11 +33,27 @@ struct RA_DATAFLOW_API EditableParameterBase {

template <typename T>
struct EditableParameter : public EditableParameterBase {
EditableParameter() = delete;
explicit EditableParameter( std::string name, T& data );
/// \name Constructors
/// @{
/// \brief delete default constructors.
EditableParameter() = delete;
EditableParameter( const EditableParameter& ) = delete;
EditableParameter& operator=( const EditableParameter& ) = delete;

/// Construct an editable parameter from its name and type hash
EditableParameter( std::string name, T& data );
///@}

/// Add constraints or associated data to the editable.
/// \todo, replace this with a json object describing the constraints
/// with value convertible to T ....
void addAdditionalData( T newData );

/// The data to edit.
/// This is a reference to any data stored in a node and that the user could change
T& m_data;

/// Constraints on the edited data
std::vector<T> additionalData;
};

Expand Down
4 changes: 4 additions & 0 deletions src/Dataflow/Core/Enumerator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ namespace Ra {
namespace Dataflow {
namespace Core {

/**
* \brief Allow to manage
* \tparam T
*/
template <typename T>
class Enumerator : public Ra::Core::Utils::Observable<const Enumerator<T>&>
{
Expand Down
31 changes: 21 additions & 10 deletions src/Dataflow/Core/Nodes/CoreBuiltInsNodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ namespace NodeFactoriesManager {
FACTORY->registerNodeCreator<NAMESPACE::ArrayMapper##SUFFIX>( \
NAMESPACE::ArrayMapper##SUFFIX::getTypename() + "_", #NAMESPACE )

#define ADD_SOURCES_TO_FACTORY( FACTORY, NAMESPACE, SUFFIX ) \
FACTORY->registerNodeCreator<NAMESPACE::ArrayDataSource##SUFFIX>( \
NAMESPACE::ArrayDataSource##SUFFIX::getTypename() + "_", #NAMESPACE )

void registerStandardFactories() {
NodeFactorySet::mapped_type coreFactory { new NodeFactorySet::mapped_type::element_type(
NodeFactoriesManager::dataFlowBuiltInsFactoryName ) };
Expand All @@ -31,16 +35,23 @@ void registerStandardFactories() {
Sources::ScalarValueSource::getTypename() + "_", "Source" );
coreFactory->registerNodeCreator<Sources::ColorSourceNode>(
Sources::ColorSourceNode::getTypename() + "_", "Source" );
coreFactory->registerNodeCreator<Sources::FloatArrayDataSource>(
Sources::FloatArrayDataSource::getTypename() + "_", "Source" );
coreFactory->registerNodeCreator<Sources::DoubleArrayDataSource>(
Sources::DoubleArrayDataSource::getTypename() + "_", "Source" );
coreFactory->registerNodeCreator<Sources::IntArrayDataSource>(
Sources::IntArrayDataSource::getTypename() + "_", "Source" );
coreFactory->registerNodeCreator<Sources::UIntArrayDataSource>(
Sources::UIntArrayDataSource::getTypename() + "_", "Source" );
coreFactory->registerNodeCreator<Sources::ColorArrayDataSource>(
Sources::ColorArrayDataSource::getTypename() + "_", "Source" );

ADD_SOURCES_TO_FACTORY( coreFactory, Sources, Float );
ADD_SOURCES_TO_FACTORY( coreFactory, Sources, Int );
ADD_SOURCES_TO_FACTORY( coreFactory, Sources, UInt );
ADD_SOURCES_TO_FACTORY( coreFactory, Sources, Color );
ADD_SOURCES_TO_FACTORY( coreFactory, Sources, Vector2f );
ADD_SOURCES_TO_FACTORY( coreFactory, Sources, Vector2d );
ADD_SOURCES_TO_FACTORY( coreFactory, Sources, Vector3f );
ADD_SOURCES_TO_FACTORY( coreFactory, Sources, Vector3d );
ADD_SOURCES_TO_FACTORY( coreFactory, Sources, Vector4f );
ADD_SOURCES_TO_FACTORY( coreFactory, Sources, Vector4d );
ADD_SOURCES_TO_FACTORY( coreFactory, Sources, Vector2i );
ADD_SOURCES_TO_FACTORY( coreFactory, Sources, Vector2ui );
ADD_SOURCES_TO_FACTORY( coreFactory, Sources, Vector3i );
ADD_SOURCES_TO_FACTORY( coreFactory, Sources, Vector3ui );
ADD_SOURCES_TO_FACTORY( coreFactory, Sources, Vector4i );
ADD_SOURCES_TO_FACTORY( coreFactory, Sources, Vector4ui );

/* --- Sinks --- */
coreFactory->registerNodeCreator<Sinks::BooleanSink>( Sinks::BooleanSink::getTypename() + "_",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma once

#include <Dataflow/Core/Nodes/Sources/CoreDataSources.hpp>

#include <Core/Utils/TypesUtils.hpp>
Expand All @@ -9,111 +9,111 @@ namespace Core {
namespace Sources {

/* Source bool */
inline BooleanValueSource::BooleanValueSource( const std::string& name ) :
BooleanValueSource::BooleanValueSource( const std::string& name ) :
SingleDataSourceNode( name, BooleanValueSource::getTypename() ) {
setEditable( "boolean" );
}

inline void BooleanValueSource::toJsonInternal( nlohmann::json& data ) const {
void BooleanValueSource::toJsonInternal( nlohmann::json& data ) const {
data["boolean"] = *getData();
}

inline void BooleanValueSource::fromJsonInternal( const nlohmann::json& data ) {
void BooleanValueSource::fromJsonInternal( const nlohmann::json& data ) {
if ( data.contains( "boolean" ) ) {
bool v = data["boolean"];
setData( v );
}
}

inline const std::string& BooleanValueSource::getTypename() {
const std::string& BooleanValueSource::getTypename() {
static std::string demangledTypeName { "Source<bool>" };
return demangledTypeName;
}

/* Source int */
inline IntValueSource::IntValueSource( const std::string& name ) :
IntValueSource::IntValueSource( const std::string& name ) :
SingleDataSourceNode( name, IntValueSource::getTypename() ) {
setEditable( "value" );
}

inline void IntValueSource::toJsonInternal( nlohmann::json& data ) const {
void IntValueSource::toJsonInternal( nlohmann::json& data ) const {
data["value"] = *getData();
}

inline void IntValueSource::fromJsonInternal( const nlohmann::json& data ) {
void IntValueSource::fromJsonInternal( const nlohmann::json& data ) {
if ( data.contains( "value" ) ) {
int v = data["value"];
setData( v );
}
}

inline const std::string& IntValueSource::getTypename() {
const std::string& IntValueSource::getTypename() {
static std::string demangledTypeName { "Source<int>" };
return demangledTypeName;
}

/* Source uint */
inline UIntValueSource::UIntValueSource( const std::string& name ) :
UIntValueSource::UIntValueSource( const std::string& name ) :
SingleDataSourceNode( name, UIntValueSource::getTypename() ) {
setEditable( "value" );
}

inline void UIntValueSource::toJsonInternal( nlohmann::json& data ) const {
void UIntValueSource::toJsonInternal( nlohmann::json& data ) const {
data["value"] = *getData();
}

inline void UIntValueSource::fromJsonInternal( const nlohmann::json& data ) {
void UIntValueSource::fromJsonInternal( const nlohmann::json& data ) {
if ( data.contains( "value" ) ) {
unsigned int v = data["value"];
setData( v );
}
}

inline const std::string& UIntValueSource::getTypename() {
const std::string& UIntValueSource::getTypename() {
static std::string demangledTypeName { "Source<uint>" };
return demangledTypeName;
}

/* Source Scalar */
inline const std::string& ScalarValueSource::getTypename() {
const std::string& ScalarValueSource::getTypename() {
static std::string demangledTypeName { "Source<Scalar>" };
return demangledTypeName;
}

inline ScalarValueSource::ScalarValueSource( const std::string& name ) :
ScalarValueSource::ScalarValueSource( const std::string& name ) :
SingleDataSourceNode( name, ScalarValueSource::getTypename() ) {
setEditable( "number" );
}

inline void ScalarValueSource::toJsonInternal( nlohmann::json& data ) const {
void ScalarValueSource::toJsonInternal( nlohmann::json& data ) const {
data["number"] = *getData();
}

inline void ScalarValueSource::fromJsonInternal( const nlohmann::json& data ) {
void ScalarValueSource::fromJsonInternal( const nlohmann::json& data ) {
if ( data.contains( "number" ) ) {
Scalar v = data["number"];
setData( v );
}
}

/* Source Color */
inline const std::string& ColorSourceNode::getTypename() {
const std::string& ColorSourceNode::getTypename() {
static std::string demangledTypeName { "Source<RaColor>" };
return demangledTypeName;
}

inline ColorSourceNode::ColorSourceNode( const std::string& name ) :
ColorSourceNode::ColorSourceNode( const std::string& name ) :
SingleDataSourceNode( name, ColorSourceNode::getTypename() ) {
setEditable( "color" );
}

inline void ColorSourceNode::toJsonInternal( nlohmann::json& data ) const {
void ColorSourceNode::toJsonInternal( nlohmann::json& data ) const {
auto c = Ra::Core::Utils::Color::linearRGBTosRGB( *getData() );
std::array<Scalar, 3> color { { c.x(), c.y(), c.z() } };
data["color"] = color;
}

inline void ColorSourceNode::fromJsonInternal( const nlohmann::json& data ) {
void ColorSourceNode::fromJsonInternal( const nlohmann::json& data ) {
if ( data.contains( "color" ) ) {
std::array<Scalar, 3> c = data["color"];
auto v =
Expand Down
33 changes: 26 additions & 7 deletions src/Dataflow/Core/Nodes/Sources/CoreDataSources.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <Dataflow/Core/Nodes/Sources/SingleDataSourceNode.hpp>

#include <Core/Containers/VectorArray.hpp>
#include <Core/Types.hpp>
#include <Core/Utils/Color.hpp>

#include <iostream>
Expand Down Expand Up @@ -91,15 +92,33 @@ class RA_DATAFLOW_API ColorSourceNode : public SingleDataSourceNode<Ra::Core::Ut
static const std::string& getTypename();
};

using FloatArrayDataSource = SingleDataSourceNode<Ra::Core::VectorArray<float>>;
using DoubleArrayDataSource = SingleDataSourceNode<Ra::Core::VectorArray<double>>;
using IntArrayDataSource = SingleDataSourceNode<Ra::Core::VectorArray<int>>;
using UIntArrayDataSource = SingleDataSourceNode<Ra::Core::VectorArray<unsigned int>>;
using ColorArrayDataSource = SingleDataSourceNode<Ra::Core::VectorArray<Ra::Core::Utils::Color>>;
// This macro does not end with semicolon. To be added when callin it
#define DECLARE_ARRAYSOURCES( SUFFIX, TYPE ) \
using ArrayDataSource##SUFFIX = SingleDataSourceNode<Ra::Core::VectorArray<TYPE>>

using namespace Ra::Core;

DECLARE_ARRAYSOURCES( Float, float );
DECLARE_ARRAYSOURCES( Double, double );
DECLARE_ARRAYSOURCES( Int, int );
DECLARE_ARRAYSOURCES( UInt, unsigned int );
DECLARE_ARRAYSOURCES( Color, Utils::Color );
DECLARE_ARRAYSOURCES( Vector2f, Vector2f );
DECLARE_ARRAYSOURCES( Vector2d, Vector2d );
DECLARE_ARRAYSOURCES( Vector3f, Vector3f );
DECLARE_ARRAYSOURCES( Vector3d, Vector3d );
DECLARE_ARRAYSOURCES( Vector4f, Vector4f );
DECLARE_ARRAYSOURCES( Vector4d, Vector4d );
DECLARE_ARRAYSOURCES( Vector2i, Vector2i );
DECLARE_ARRAYSOURCES( Vector3i, Vector3i );
DECLARE_ARRAYSOURCES( Vector4i, Vector4i );
DECLARE_ARRAYSOURCES( Vector2ui, Vector2ui );
DECLARE_ARRAYSOURCES( Vector3ui, Vector3ui );
DECLARE_ARRAYSOURCES( Vector4ui, Vector4ui );

#undef DECLARE_ARRAYSOURCES

} // namespace Sources
} // namespace Core
} // namespace Dataflow
} // namespace Ra

#include <Dataflow/Core/Nodes/Sources/CoreDataSources.inl>
5 changes: 3 additions & 2 deletions src/Dataflow/Core/filelist.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
# from ./scripts directory
# ----------------------------------------------------

set(dataflow_core_sources DataflowGraph.cpp Node.cpp NodeFactory.cpp Nodes/CoreBuiltInsNodes.cpp)
set(dataflow_core_sources DataflowGraph.cpp Node.cpp NodeFactory.cpp Nodes/CoreBuiltInsNodes.cpp
Nodes/Sources/CoreDataSources.cpp
)

set(dataflow_core_headers
DataflowGraph.hpp
Expand Down Expand Up @@ -35,7 +37,6 @@ set(dataflow_core_inlines
Nodes/Functionals/MapNode.inl
Nodes/Sinks/CoreDataSinks.inl
Nodes/Sinks/SinkNode.inl
Nodes/Sources/CoreDataSources.inl
Nodes/Sources/FunctionSource.inl
Nodes/Sources/SingleDataSourceNode.inl
Port.inl
Expand Down

0 comments on commit 684d411

Please sign in to comment.