Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 33 additions & 19 deletions misc/devtools/include/inviwo/devtools/processors/eventlogger.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,22 @@

namespace inviwo {

template <typename Inport, typename Outport>
template <typename InportType, typename OutportType>
class EventLogger : public Processor {
public:
EventLogger();
virtual ~EventLogger() = default;

virtual void process() override;
virtual const ProcessorInfo& getProcessorInfo() const override;
virtual void invokeEvent(Event* event) override;
virtual void propagateEvent(Event* event, Outport* source) override;

private:
Inport inport_;
Outport outport_;
InportType inport_;
OutportType outport_;
BoolCompositeProperty enable_;
BoolProperty logBefore_;
BoolProperty logAfter_;
ButtonGroupProperty eventToggle_;

static constexpr size_t eventCount = 7;
Expand All @@ -83,12 +85,14 @@ class EventLogger : public Processor {
BoolProperty enableOtherEvents_;
};

template <typename Inport, typename Outport>
EventLogger<Inport, Outport>::EventLogger()
template <typename InportType, typename OutportType>
EventLogger<InportType, OutportType>::EventLogger()
: Processor()
, inport_("inport", "The inport, only used for pass through."_help)
, outport_("outport")
, enable_("enable", "Enable Logging", "Enable or disable logging of events."_help, true)
, logBefore_{"logBefore", "Log Before", true}
, logAfter_{"logAfter", "Log After", false}
, eventToggle_("eventToggle", "Toggle Events",
{{"Set All", std::nullopt, "Enable logging of all event types",
[this]() {
Expand Down Expand Up @@ -123,34 +127,44 @@ EventLogger<Inport, Outport>::EventLogger()
addPort(inport_);
addPort(outport_);
addProperty(enable_);
enable_.addProperty(eventToggle_);
enable_.addProperties(logBefore_, logAfter_, eventToggle_);

for (auto& p : enableEvents_) {
enable_.addProperty(p);
}
enable_.addProperty(enableOtherEvents_);
}

template <typename Inport, typename Outport>
void EventLogger<Inport, Outport>::process() {
template <typename InportType, typename OutportType>
void EventLogger<InportType, OutportType>::process() {
outport_.setData(inport_.getData());
}

template <typename Inport, typename Outport>
void EventLogger<Inport, Outport>::invokeEvent(Event* event) {
if (!enable_) return;
template <typename InportType, typename OutportType>
void EventLogger<InportType, OutportType>::propagateEvent(Event* event, Outport* source) {
if (enable_ && logBefore_) {
const auto it = eventMap_.find(event->hash());
if ((it == eventMap_.end() && enableOtherEvents_.get()) ||
(it != eventMap_.end() && it->second.get())) {
log::info("{:20} {}", getDisplayName(), *event);
}
}

const auto it = eventMap_.find(event->hash());
if ((it == eventMap_.end() && enableOtherEvents_.get()) ||
(it != eventMap_.end() && it->second.get())) {
log::info("{:25} {}", getDisplayName(), *event);
Processor::propagateEvent(event, source);

if (enable_ && logAfter_) {
const auto it = eventMap_.find(event->hash());
if ((it == eventMap_.end() && enableOtherEvents_.get()) ||
(it != eventMap_.end() && it->second.get())) {
log::info("{:20} {}", getDisplayName(), *event);
}
}
}

template <typename Inport, typename Outport>
const ProcessorInfo& EventLogger<Inport, Outport>::getProcessorInfo() const {
template <typename InportType, typename OutportType>
const ProcessorInfo& EventLogger<InportType, OutportType>::getProcessorInfo() const {
static const ProcessorInfo info{
ProcessorTraits<EventLogger<Inport, Outport>>::getProcessorInfo()};
ProcessorTraits<EventLogger<InportType, OutportType>>::getProcessorInfo()};
return info;
}

Expand Down
7 changes: 3 additions & 4 deletions misc/graphviz/src/graphvizsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include <inviwo/core/metadata/processormetadata.h>
#include <inviwo/core/util/stringconversion.h>
#include <inviwo/core/network/networkutils.h>
#include <inviwo/core/util/safecstr.h>
#include <inviwo/graphviz/graphvizutil.h>

#include <graphviz/cgraph.h>
Expand Down Expand Up @@ -158,8 +159,7 @@ void calculateLayout(StrBuffer& buff, ProcessorNetwork* net, const Func& func) {
ivec2 center{0};
int count = 0;
net->forEachProcessor([&](Processor* p) {
const std::string identifier{p->getIdentifier()};
if (auto* n = agnode(G, const_cast<char*>(identifier.c_str()), 0)) {
if (auto* n = agnode(G, const_cast<char*>(SafeCStr{p->getIdentifier()}.c_str()), 0)) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy diagnostic

misc/graphviz/src/graphvizsettings.cpp:162:37: warning: [cppcoreguidelines-pro-type-const-cast]

do not use const_cast to remove const qualifier

  162 |             if (auto* n = agnode(G, const_cast<char*>(SafeCStr{p->getIdentifier()}.c_str()), 0)) {
      |                                     ^

const auto& coord = ND_coord(n);
center += ivec2{coord.x, -coord.y};
++count;
Expand All @@ -174,8 +174,7 @@ void calculateLayout(StrBuffer& buff, ProcessorNetwork* net, const Func& func) {
const dvec2 offset = oldCenter - newCenter;

net->forEachProcessor([&](Processor* p) {
const std::string identifier{p->getIdentifier()};
if (auto* n = agnode(G, const_cast<char*>(identifier.c_str()), 0)) {
if (auto* n = agnode(G, const_cast<char*>(SafeCStr{p->getIdentifier()}.c_str()), 0)) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy diagnostic

misc/graphviz/src/graphvizsettings.cpp:177:33: warning: [cppcoreguidelines-pro-type-const-cast]

do not use const_cast to remove const qualifier

  177 |         if (auto* n = agnode(G, const_cast<char*>(SafeCStr{p->getIdentifier()}.c_str()), 0)) {
      |                                 ^

const auto& coord = ND_coord(n);
func(p, dvec2{coord.x, -coord.y} + offset);
}
Expand Down
8 changes: 8 additions & 0 deletions misc/vtk/include/inviwo/vtk/ports/vtkinport.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ namespace inviwo {

namespace vtk {

class VtkOutport;

class IVW_MODULE_VTK_API VtkInport : public Inport {
public:
enum class Repeatable : std::uint8_t { Yes, No };
Expand All @@ -59,7 +61,12 @@ class IVW_MODULE_VTK_API VtkInport : public Inport {
using type = vtkDataObject;

virtual bool canConnectTo(const Port* port) const override;
virtual void connectTo(Outport* outport) override;
virtual void disconnectFrom(Outport* outport) override;

virtual Outport* getConnectedOutport(size_t i) const override;
virtual size_t getMaxNumberOfConnections() const override;
virtual size_t getNumberOfConnections() const override;
virtual std::string_view getClassIdentifier() const override;
virtual glm::uvec3 getColorCode() const override;
virtual Document getInfo() const override;
Expand All @@ -71,6 +78,7 @@ class IVW_MODULE_VTK_API VtkInport : public Inport {
void setTypeId(int typeId);

private:
std::vector<VtkOutport*> outports_;
int typeId_;
Repeatable repeatable_;
};
Expand Down
44 changes: 39 additions & 5 deletions misc/vtk/src/ports/vtkinport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,48 @@ bool VtkInport::canConnectTo(const Port* port) const {
}
return false;
}

void VtkInport::connectTo(Outport* outport) {
if (!outport) return;
if (isConnectedTo(outport)) return;

if (auto* vtkOutport = dynamic_cast<VtkOutport*>(outport)) {
if (getNumberOfConnections() + 1 > getMaxNumberOfConnections()) {
throw Exception("Trying to connect to a full port.");
}
outports_.push_back(vtkOutport);

doConnectTo(outport);
} else {
throw Exception("Trying to connect incompatible ports.");
}
}
void VtkInport::disconnectFrom(Outport* outport) {
if (auto it = std::ranges::find_if(outports_, [&](VtkOutport* p) { return p == outport; });
it != outports_.end()) {

outports_.erase(it);
doDisconnectFrom(outport);
}
}

Outport* VtkInport::getConnectedOutport(size_t i) const {
if (i < outports_.size()) {
return outports_[i];
} else {
return nullptr;
}
}

size_t VtkInport::getMaxNumberOfConnections() const {
return repeatable_ == Repeatable::Yes ? std::numeric_limits<size_t>::max() : 1;
}

size_t VtkInport::getNumberOfConnections() const { return outports_.size(); }

vtkDataObject* VtkInport::getData(size_t i) const {
if (i < connectedOutports_.size()) {
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-static-cast-downcast)
return static_cast<VtkOutport*>(connectedOutports_[i])->getData();
if (i < outports_.size()) {
return outports_[i]->getData();
}
return nullptr;
}
Expand Down Expand Up @@ -153,8 +187,8 @@ int VtkInport::getTypeId() const { return typeId_; }

void VtkInport::setTypeId(int typeId) {
typeId_ = typeId;
std::vector<Outport*> portsToRemove =
util::copy_if(connectedOutports_, [&](auto port) { return !canConnectTo(port); });
std::vector<VtkOutport*> portsToRemove =

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy diagnostics

  • variable 'portsToRemove' of type 'std::vector<VtkOutport *>' can be declared 'const' [misc-const-correctness]
Suggested change
std::vector<VtkOutport*> portsToRemove =
const std::vector<VtkOutport*> portsToRemove =

util::copy_if(outports_, [&](auto port) { return !canConnectTo(port); });
for (auto outport : portsToRemove) {
getProcessor()->getNetwork()->removeConnection(outport, this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ struct IVW_MODULE_TENSORVISBASE_API InvariantSpace {
else
return data_[0]->size();
}
void addAxis(const std::string& identifier, std::vector<double>* data, TensorFeature type) {
identifiers_.push_back(identifier);
void addAxis(std::string_view identifier, std::vector<double>* data, TensorFeature type) {
identifiers_.emplace_back(identifier);
metaDataTypes_.push_back(type);

auto minmax = std::minmax_element(data->begin(), data->end());
Expand All @@ -64,7 +64,7 @@ struct IVW_MODULE_TENSORVISBASE_API InvariantSpace {

template <typename T>
void addAxis(const tensor::MetaDataType<T>* metaData, std::string_view name = "") {
identifiers_.push_back(name.empty() ? metaData->getDisplayName() : std::string{name});
identifiers_.emplace_back(name.empty() ? metaData->getDisplayName() : name);
metaDataTypes_.push_back(metaData->type_);
minmax_.push_back({{metaData->getMinMax().first, metaData->getMinMax().second}});

Expand Down
Loading