Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • LidarView/lidarview-core
  • nick.laurenson/lidarview-core
  • aerezarang/lidarview-core
3 results
Show changes
Commits on Source (7)
Showing
with 845 additions and 0 deletions
......@@ -26,13 +26,24 @@ add_library(lqApplicationComponents
lqStreamRecordDialog.h
lqStreamRecordReaction.cxx
lqStreamRecordReaction.h
SaveAndLoadLidarState/lqSaveLidarStateReaction.cxx
SaveAndLoadLidarState/lqSaveLidarStateReaction.h
SaveAndLoadLidarState/lqLoadLidarStateReaction.cxx
SaveAndLoadLidarState/lqLoadLidarStateReaction.h
SaveAndLoadLidarState/lqLidarStateDialog.cxx
SaveAndLoadLidarState/lqLidarStateDialog.h
lqResources.qrc
)
target_include_directories(lqApplicationComponents PUBLIC
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/ctk/
${CMAKE_CURRENT_SOURCE_DIR}/SaveAndLoadLidarState/
${CMAKE_CURRENT_BINARY_DIR}
)
target_sources(lqApplicationComponents PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/lqHelper.cxx
)
target_link_libraries(lqApplicationComponents
PUBLIC
pqApplicationComponents
......
ApplicationComponents/Icons/pqLoadState.png

33.4 KiB

<svg id="Layer_1" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64"><title>SVG_Artboards</title><path d="M56.45,37.88H8a3.31,3.31,0,0,0-3.31,3.3V55.73A3.31,3.31,0,0,0,8,59H56.45a3.31,3.31,0,0,0,3.3-3.31V41.18A3.3,3.3,0,0,0,56.45,37.88Zm-43,13.2a2.62,2.62,0,1,1,2.62-2.62A2.63,2.63,0,0,1,13.44,51.08Z" style="fill:#cdcece"/><path d="M56.45,60.16H8a4.43,4.43,0,0,1-4.43-4.43V41.18A4.43,4.43,0,0,1,8,36.75H56.45a4.44,4.44,0,0,1,4.43,4.43V55.73A4.43,4.43,0,0,1,56.45,60.16ZM8,39a2.19,2.19,0,0,0-2.18,2.18V55.73A2.19,2.19,0,0,0,8,57.91H56.45a2.19,2.19,0,0,0,2.18-2.18V41.18A2.19,2.19,0,0,0,56.45,39Zm5.45,13.2a3.75,3.75,0,1,1,3.75-3.74A3.75,3.75,0,0,1,13.44,52.2Zm0-5.24a1.5,1.5,0,1,0,1.5,1.5A1.5,1.5,0,0,0,13.44,47Z" style="fill:#787878"/><polygon points="15.65 29.2 32.74 3.42 49.84 29.2 40.77 29.2 40.77 47.35 24.73 47.35 24.73 29.2 15.65 29.2" style="fill:#2896d3"/><path d="M40.76,48.48h-16a1.14,1.14,0,0,1-1.13-1.13v-17h-8a1.12,1.12,0,0,1-1-.6,1.11,1.11,0,0,1,.05-1.15L31.8,2.8a1.14,1.14,0,0,1,.94-.5h0a1.14,1.14,0,0,1,.94.5l17.1,25.78a1.11,1.11,0,0,1,.06,1.15,1.13,1.13,0,0,1-1,.6h-8v17A1.13,1.13,0,0,1,40.76,48.48Zm-14.9-2.26H39.64v-17a1.13,1.13,0,0,1,1.12-1.13h7l-15-22.61-15,22.61h7a1.14,1.14,0,0,1,1.13,1.13Z" style="fill:#6f6f59"/></svg>
ApplicationComponents/Icons/pqSaveState.png

32.8 KiB

<svg id="Layer_1" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64"><title>SVG_Artboards</title><path d="M56.4,37.88H7.94a3.3,3.3,0,0,0-3.3,3.3V55.73A3.31,3.31,0,0,0,7.94,59H56.4a3.31,3.31,0,0,0,3.31-3.31V41.18A3.31,3.31,0,0,0,56.4,37.88Zm-43,13.2A2.62,2.62,0,1,1,16,48.46,2.62,2.62,0,0,1,13.4,51.08Z" style="fill:#cdcece"/><path d="M56.4,60.16H7.94a4.43,4.43,0,0,1-4.43-4.43V41.18a4.44,4.44,0,0,1,4.43-4.43H56.4a4.43,4.43,0,0,1,4.43,4.43V55.73A4.43,4.43,0,0,1,56.4,60.16ZM7.94,39a2.18,2.18,0,0,0-2.17,2.18V55.73a2.18,2.18,0,0,0,2.17,2.18H56.4a2.19,2.19,0,0,0,2.18-2.18V41.18A2.19,2.19,0,0,0,56.4,39ZM13.4,52.2a3.75,3.75,0,1,1,3.75-3.74A3.76,3.76,0,0,1,13.4,52.2Zm0-5.24a1.5,1.5,0,1,0,1.49,1.5A1.5,1.5,0,0,0,13.4,47Z" style="fill:#787878"/><polygon points="49.27 21.57 32.18 47.35 15.08 21.57 24.16 21.57 24.16 3.42 40.19 3.42 40.19 21.57 49.27 21.57" style="fill:#a7d28c"/><path d="M32.18,48.48a1.1,1.1,0,0,1-.93-.51L14.14,22.2a1.12,1.12,0,0,1,.94-1.75h8v-17A1.12,1.12,0,0,1,24.16,2.3h16a1.13,1.13,0,0,1,1.13,1.12v17h8a1.13,1.13,0,0,1,.94,1.75L33.12,48a1.12,1.12,0,0,1-.94.51Zm-15-25.78,15,22.61,15-22.61h-7a1.13,1.13,0,0,1-1.13-1.13v-17H25.28v17a1.12,1.12,0,0,1-1.12,1.13Z" style="fill:#6f6f59"/></svg>
#include "lqLidarStateDialog.h"
#include <QLabel>
#include <QPushButton>
#include <string>
//-----------------------------------------------------------------------------
lqLidarStateDialog::lqLidarStateDialog(QWidget *parent,
std::vector<propertyInfo>& propertiesVector) :
QDialog(parent)
{
this->properties = propertiesVector;
QVBoxLayout* vbox = new QVBoxLayout;
this->CreateDialog(vbox);
// Add a QPushbutton
QPushButton * button = new QPushButton("OK");
this->connect(button, SIGNAL(pressed()), this, SLOT(accept()));
vbox->addWidget(button);
this->setLayout(vbox);
}
//-----------------------------------------------------------------------------
void lqLidarStateDialog::CreateDialog(QVBoxLayout *vbox)
{
for(unsigned int i = 0; i < this->properties.size(); i++)
{
propertyInfo currentProperty = this->properties[i];
std::string proxyName = currentProperty.proxyName;
// The property is the name of a proxy : we display it as a title
if(currentProperty.isProxy())
{
QLabel * label = new QLabel(QString(proxyName.c_str()));
label->setStyleSheet("font-weight: bold;font-size: 14px ; color: black");
vbox->addWidget(label, 0, Qt::AlignCenter);
}
else
{
std::string value = currentProperty.getValuesAsSingleString();
QHBoxLayout* hboxLayout = new QHBoxLayout();
QLabel* label = new QLabel(value.c_str());
hboxLayout->addWidget(currentProperty.checkbox, 0, Qt::AlignLeft);
hboxLayout->addWidget(label, 0, Qt::AlignLeft);
vbox->addLayout(hboxLayout);
}
}
}
#ifndef LQLIDARSTATEDIALOG_H
#define LQLIDARSTATEDIALOG_H
#include <QDialog>
#include <QVBoxLayout>
#include <QCheckBox>
#include <cstring>
#include <vector>
class propertyInfo
{
public:
propertyInfo(std::string _proxyName, std::string _propName):
proxyName(_proxyName), propertyName(_propName)
{initCheckbox();}
propertyInfo(std::string _proxyName, std::string _propName, std::vector<std::string>& _values):
proxyName(_proxyName), propertyName(_propName), values(_values){initCheckbox();}
std::string proxyName;
std::string propertyName;
std::vector<std::string> values;
QCheckBox * checkbox;
void initCheckbox()
{
checkbox = new QCheckBox(QString(propertyName.c_str()));
checkbox ->setChecked(false);
checkbox ->setCheckable(true);
}
std::string getCheckboxLabel()
{
return checkbox->text().toStdString();
}
bool isProxy()
{
return (proxyName.compare(this->propertyName) == 0);
}
std::string getValuesAsSingleString()
{
std::string concatenateAllValues = "";
for(unsigned int i = 0; i < this->values.size(); i++)
{
if(i != 0)
{
concatenateAllValues = concatenateAllValues + " ";
}
concatenateAllValues = concatenateAllValues + values[i];
}
return concatenateAllValues;
}
};
/**
* @brief Dialog so the user can select the properties of a proxy to save
*/
class lqLidarStateDialog : public QDialog
{
Q_OBJECT
public:
explicit lqLidarStateDialog(QWidget *parent, std::vector<propertyInfo>& propertiesVector);
~lqLidarStateDialog(){}
void CreateDialog(QVBoxLayout * vbox);
std::vector<propertyInfo> properties;
};
#endif // LQLIDARSTATEDIALOG_H
#include "lqLoadLidarStateReaction.h"
#include "lqHelper.h"
#include <QDir>
#include <QFileDialog>
#include <QFileInfo>
#include <QMessageBox>
#include <pqApplicationCore.h>
#include <pqPipelineSource.h>
#include <pqServerManagerModel.h>
#include <vtkSmartPointer.h>
#include <vtkSMProxy.h>
#include <vtkSMProperty.h>
#include <vtkSMPropertyIterator.h>
#include <vtkSMPropertyHelper.h>
#include <vtkSMBooleanDomain.h>
#include <cstring>
#include <vector>
#include <iostream>
#include <exception>
//-----------------------------------------------------------------------------
lqLoadLidarStateReaction::lqLoadLidarStateReaction(QAction *action)
: Superclass(action)
{
}
//-----------------------------------------------------------------------------
void lqLoadLidarStateReaction::onTriggered()
{
// Get the Lidar state file
QString LidarStateFile = QFileDialog::getOpenFileName(nullptr,
QString("Choose the lidar state file to load on the first lidar"),
"", QString("json (*.json)"));
if(LidarStateFile.isEmpty())
{
return;
}
// Get the first lidar source
pqServerManagerModel* smmodel = pqApplicationCore::instance()->getServerManagerModel();
if(smmodel == nullptr)
{
return;
}
vtkSMProxy * lidarCurrentProxy = nullptr;
foreach (pqPipelineSource* src, smmodel->findItems<pqPipelineSource*>())
{
if(IsLidarProxy(src->getProxy()))
{
if(lidarCurrentProxy == nullptr)
{
lidarCurrentProxy = src->getProxy();
}
else
{
QMessageBox::warning(nullptr, tr(""), tr("Multiple lidars sources found, only the first one will be updated") );
}
}
}
if(lidarCurrentProxy == nullptr)
{
QMessageBox::warning(nullptr, tr(""), tr("No lidar source found in the pipeline") );
return;
}
// Read and get information of the JSON file
Json::Value contents;
std::ifstream file(LidarStateFile.toStdString());
try
{
file >> contents;
}
catch(std::exception e)
{
QMessageBox::warning(nullptr, tr(""), tr("Json file not valid") );
return;
}
// Read the Json file
std::vector<propertyInfo> propertyInfo;
try
{
this->ParseJsonContent(contents, "",propertyInfo);
}
catch(std::exception e)
{
QMessageBox::warning(nullptr, tr(""), tr("Error when parsing json information") );
return;
}
lqLidarStateDialog dialog(nullptr, propertyInfo);
if(dialog.exec())
{
for(const auto & currentProp : dialog.properties)
{
if(currentProp.checkbox->isChecked())
{
std::string proxyName = currentProp.proxyName;
std::string propertyName = currentProp.propertyName;
vtkSMProxy* lidarProxy = this->SearchProxy(lidarCurrentProxy, proxyName);
if (lidarProxy == nullptr)
{
std::string message = "No matching proxy found. Property " + propertyName + " of the proxy " + proxyName + " not applied";
QMessageBox::information(nullptr, tr(""), tr(message.c_str()) );
}
else
{
this->UpdateProperty(lidarProxy, propertyName, currentProp.values);
}
}
}
//Update the proxy
lidarCurrentProxy->UpdateSelfAndAllInputs();
}
}
//-----------------------------------------------------------------------------
void lqLoadLidarStateReaction::ParseJsonContent(Json::Value contents, std::string ObjectName,
std::vector<propertyInfo>& propertiesInfo)
{
for(auto it = contents.begin(); it != contents.end(); it++)
{
std::string currentKey = it.key().asString();
// If the content is an object, it is write as a title
if(contents[currentKey].isObject())
{
propertyInfo prop = propertyInfo(currentKey, currentKey);
propertiesInfo.push_back(prop);
ParseJsonContent(contents[currentKey], currentKey, propertiesInfo);
}
else
{
std::vector<std::string> values;
if(contents[currentKey].isArray())
{
for(unsigned int j = 0; j < contents[currentKey].size(); j++)
{
values.push_back(contents[currentKey][j].asString());
}
}
// All data are saved as String so we don't need other case (Numeric, bool)
else if (contents[currentKey].isString())
{
values.push_back(contents[currentKey].asString());
}
propertyInfo prop = propertyInfo(ObjectName, currentKey, values);
propertiesInfo.push_back(prop);
}
}
}
//-----------------------------------------------------------------------------
vtkSMProxy* lqLoadLidarStateReaction::SearchProxy(vtkSMProxy * base_proxy,
std::string proxyName)
{
if(std::strcmp(base_proxy->GetXMLName(), proxyName.c_str()) == 0)
{
return base_proxy;
}
vtkSmartPointer<vtkSMPropertyIterator> propIter;
propIter.TakeReference(base_proxy->NewPropertyIterator());
for (propIter->Begin(); !propIter->IsAtEnd(); propIter->Next())
{
vtkSMProperty* prop = propIter->GetProperty();
// If the property is a valid proxy, we print all the properties of the proxy at the end
vtkSMProxy* propertyAsProxy = vtkSMPropertyHelper(prop).GetAsProxy();
if(propertyAsProxy)
{
return SearchProxy(propertyAsProxy, proxyName);
}
}
return nullptr;
}
//-----------------------------------------------------------------------------
void lqLoadLidarStateReaction::UpdateProperty(vtkSMProxy * proxy,
std::string propNameToFind,
std::vector<std::string> values)
{
// If there is no value to set, the request is skipped
if(values.size() < 1)
{
std::string message = "Property " + propNameToFind + " couldn't be applied";
QMessageBox::information(nullptr, tr(""), tr(message.c_str()) );
return;
}
vtkSmartPointer<vtkSMPropertyIterator> propIter;
propIter.TakeReference(proxy->NewPropertyIterator());
for (propIter->Begin(); !propIter->IsAtEnd(); propIter->Next())
{
vtkSMProperty* prop = propIter->GetProperty();
const char* propName = propIter->GetKey();
// If the name does not match we skip the property
if(std::strcmp(propName, propNameToFind.c_str()) != 0)
{
continue;
}
// Both properties match
std::vector<double> propertyAsDoubleArray = vtkSMPropertyHelper(prop).GetDoubleArray();
if(propertyAsDoubleArray.size() > 1)
{
if(propertyAsDoubleArray.size() != values.size())
{
std::cout << "Values to applied and base property does not have the same size" << std::endl;
}
std::vector<double> d;
for(unsigned int j = 0; j < values.size(); j++)
{
d.push_back(std::stod(values[j]));
}
vtkSMPropertyHelper(prop).Set(d.data(), d.size());
}
else
{
// If the property is a valid variant we display it to the user
vtkVariant propertyAsVariant = vtkSMPropertyHelper(prop).GetAsVariant(0);
if(propertyAsVariant.IsValid())
{
if(propertyAsVariant.IsInt())
{
vtkSMBooleanDomain * boolDomain = vtkSMBooleanDomain::SafeDownCast(prop->FindDomain("vtkSMBooleanDomain"));
if(boolDomain)
{
int value = (values[0].compare("false") == 0) ? 0 : 1;
vtkSMPropertyHelper(prop).Set(value);
}
else
{
vtkSMPropertyHelper(prop).Set(std::stoi(values[0]));
}
}
else if(propertyAsVariant.IsNumeric())
{
vtkSMPropertyHelper(prop).Set(std::stof(values[0]));
}
else if(propertyAsVariant.IsString())
{
vtkSMPropertyHelper(prop).Set(values[0].c_str());
}
}
}
}
}
#ifndef LQLOADLIDARSTATEREACTION_H
#define LQLOADLIDARSTATEREACTION_H
#include <QString>
#include "pqReaction.h"
#include "lqLidarStateDialog.h"
#include "lqapplicationcomponents_export.h"
#include <vtk_jsoncpp.h>
#include <vtkSMProxy.h>
class pqPipelineSource;
/**
* @ingroup Reactions
* Reaction to record stream data in a pcap file
*/
class LQAPPLICATIONCOMPONENTS_EXPORT lqLoadLidarStateReaction : public pqReaction
{
Q_OBJECT
typedef pqReaction Superclass;
public:
lqLoadLidarStateReaction(QAction* action);
public slots:
/**
* Called when the action is triggered.
*/
void onTriggered() override;
private:
Q_DISABLE_COPY(lqLoadLidarStateReaction)
/**
* @brief ParseJsonContent recursive function to create a std::vector
* with all properties information containing is a json value
* @param contents json value to read
* @param ObjectName name of the current proxy
* @param propertyInfo vector to write information (name, value) of the found properties
*/
void ParseJsonContent(Json::Value contents, std::string ObjectName, std::vector<propertyInfo>& propertyInfo);
/**
* @brief SearchProxy search recursively a proxy in an other one
* @param base_proxy
* @param proxyName name of the proxy to search
* @return the subproxy of name proxyname, nullptr if nothing found
*/
vtkSMProxy* SearchProxy(vtkSMProxy * base_proxy, std::string proxyName);
/**
* @brief UpdateProperty set the values to the property "propNameToFind" of the proxy
* If the property is not found in the proxy, a message is displayed but nothing is done
* @param proxy proxy where to search the property
* @param propNameToFind name of the property
* @param values properties values to set
*/
void UpdateProperty(vtkSMProxy * proxy, std::string propNameToFind,
std::vector<std::string> values);
};
#endif // LQLOADLIDARSTATEREACTION_H
#include "lqSaveLidarStateReaction.h"
#include "lqHelper.h"
#include <QDir>
#include <QFileDialog>
#include <QFileInfo>
#include <QMessageBox>
#include <pqApplicationCore.h>
#include <pqPipelineSource.h>
#include <pqServer.h>
#include <pqServerManagerModel.h>
#include <vtkSMProxy.h>
#include <vtkSMProperty.h>
#include <vtkSMPropertyIterator.h>
#include <vtkSMPropertyHelper.h>
#include <vtkSMBooleanDomain.h>
#include <vector>
//-----------------------------------------------------------------------------
lqSaveLidarStateReaction::lqSaveLidarStateReaction(QAction *action)
: Superclass(action)
{
}
//-----------------------------------------------------------------------------
void lqSaveLidarStateReaction::onTriggered()
{
// Save Lidar Save information file
QString defaultFileName = QString("SaveLidarInformation.json");
QString StateFile = QFileDialog::getSaveFileName(nullptr,
QString("File to save the first lidar information:"),
defaultFileName, QString("json (*.json)"));
if(StateFile.isEmpty())
{
return;
}
// Get the first lidar source
pqServerManagerModel* smmodel = pqApplicationCore::instance()->getServerManagerModel();
if(smmodel == nullptr)
{
return;
}
vtkSMProxy * lidarProxy = nullptr;
foreach (pqPipelineSource* src, smmodel->findItems<pqPipelineSource*>())
{
if(IsLidarProxy(src->getProxy()))
{
if(lidarProxy == nullptr)
{
lidarProxy = src->getProxy();
}
else
{
QMessageBox::warning(nullptr, tr(""), tr("Multiple lidars sources found, only the first one will be saved") );
}
}
}
if(lidarProxy == nullptr)
{
QMessageBox::warning(nullptr, tr(""), tr("No lidar source found in the pipeline") );
return;
}
std::vector<propertyInfo> propertiesInfo;
constructPropertiesInfo(lidarProxy, propertiesInfo);
lqLidarStateDialog dialog(nullptr, propertiesInfo);
if(dialog.exec())
{
Json::StyledStreamWriter writer;
std::ofstream configFile(StateFile.toStdString());
Json::Value data;
for(unsigned int i = 0; i < dialog.properties.size(); i++)
{
propertyInfo currentProperty = dialog.properties[i];
if(currentProperty.isProxy())
{
continue;
}
if(currentProperty.checkbox->isChecked())
{
std::string proxyName = currentProperty.proxyName;
std::string propertyName = currentProperty.propertyName;
std::vector<std::string> values = currentProperty.values;
Json::Value vec(Json::arrayValue);
if(values.size() == 1)
{
data[proxyName][propertyName] = values[0];
}
else
{
for(unsigned int i = 0; i < values.size(); i++)
{
vec.append(Json::Value(values[i]));
}
data[proxyName][propertyName] = vec;
}
}
}
writer.write(configFile, data);
}
}
//-----------------------------------------------------------------------------
void lqSaveLidarStateReaction::constructPropertiesInfo(vtkSMProxy * lidarProxy,
std::vector<propertyInfo>& propertiesVector)
{
std::vector<vtkSMProxy*> proxysToCompute;
std::string proxyName = lidarProxy->GetXMLName();
// Push the proxyName into the properties vector
propertyInfo proxy = propertyInfo(proxyName, proxyName);
propertiesVector.push_back(proxy);
vtkSmartPointer<vtkSMPropertyIterator> propIter;
propIter.TakeReference(lidarProxy->NewPropertyIterator());
for (propIter->Begin(); !propIter->IsAtEnd(); propIter->Next())
{
vtkSMProperty* prop = propIter->GetProperty();
const char* propertyName = propIter->GetKey();
// Do not let the user check property that are in read only
if(prop->GetInformationOnly())
{
continue;
}
// Do not handle repeatable property
if(prop->GetRepeatable())
{
continue;
}
// If the property is a valid proxy, we print all the properties of the proxy at the end
vtkSMProxy* propertyAsProxy = vtkSMPropertyHelper(prop).GetAsProxy();
if(propertyAsProxy)
{
proxysToCompute.push_back(propertyAsProxy);
continue;
}
std::vector<std::string> values = getValueOfPropAsString(prop);
propertyInfo proxy = propertyInfo(proxyName, propertyName, values);
propertiesVector.push_back(proxy);
}
// Print all properties contains in the proxy properties
// We call the recursive function at the end
// because the dialog will take the properties in the saved order
// We want all specific properties of a proxy stick together
for(unsigned int p = 0; p < proxysToCompute.size(); p++)
{
this->constructPropertiesInfo(proxysToCompute[p], propertiesVector);
}
}
//-----------------------------------------------------------------------------
std::vector<std::string> lqSaveLidarStateReaction::getValueOfPropAsString(vtkSMProperty * prop)
{
std::vector<std::string> result;
// If the property is a valid double array we display all the element to the user
std::vector<double> propertyAsDoubleArray = vtkSMPropertyHelper(prop).GetDoubleArray();
if(propertyAsDoubleArray.size() > 1)
{
for(unsigned int j = 0; j < propertyAsDoubleArray.size(); j++)
{
result.push_back(std::to_string(propertyAsDoubleArray[j]));
}
return result;
}
else
{
// If the property is a valid variant we display it to the user
vtkVariant propertyAsVariant = vtkSMPropertyHelper(prop).GetAsVariant(0);
if(propertyAsVariant.IsValid())
{
// If the property belongs to the boolean domain we display True/False notation to the user
vtkSMBooleanDomain * boolDomain = vtkSMBooleanDomain::SafeDownCast(prop->FindDomain("vtkSMBooleanDomain"));
if(boolDomain)
{
std::string bool_to_string = (propertyAsVariant.ToInt() == 0) ? "false" : "true";
result.push_back(bool_to_string);
return result;
}
result.push_back(propertyAsVariant.ToString());
return result;
}
}
return result;
}
#ifndef LQSAVELIDARSTATEREACTION_H
#define LQSAVELIDARSTATEREACTION_H
#include <QString>
#include <pqReaction.h>
#include <vtkSMProperty.h>
#include <vtk_jsoncpp.h>
#include "lqLidarStateDialog.h"
#include "lqapplicationcomponents_export.h"
class pqPipelineSource;
/**
* @ingroup Reactions
* Reaction to record stream data in a pcap file
*/
class LQAPPLICATIONCOMPONENTS_EXPORT lqSaveLidarStateReaction : public pqReaction
{
Q_OBJECT
typedef pqReaction Superclass;
public:
lqSaveLidarStateReaction(QAction* action);
public slots:
/**
* Called when the action is triggered.
*/
void onTriggered() override;
private:
Q_DISABLE_COPY(lqSaveLidarStateReaction)
/**
* @brief constructPropertiesInfo
* @param lidarProxy proxy to extract the properties
* @param propertiesVector contains all the properties (names, value) of the current proxy and ots sub-proxy.
*/
void constructPropertiesInfo(vtkSMProxy * lidarProxy, std::vector<propertyInfo>& propertiesVector);
/**
* @brief getValueOfPropAsString get the values of a property
* @param prop property to extract value
* @return The std::vector containing the values of the property prop.
* If the property is a not an array, only the first element is fill
*/
std::vector<std::string> getValueOfPropAsString(vtkSMProperty * prop);
};
#endif // LQSAVELIDARSTATEREACTION_H
#include "lqHelper.h"
#include "vtkLidarReader.h"
#include "vtkLidarStream.h"
//-----------------------------------------------------------------------------
bool IsLidarProxy(vtkSMProxy * proxy)
{
if(proxy != nullptr)
{
auto* tmp_stream = dynamic_cast<vtkLidarStream*> (proxy->GetClientSideObject());
auto* tmp_reader = dynamic_cast<vtkLidarReader*> (proxy->GetClientSideObject());
if (tmp_stream || tmp_reader)
{
return true;
}
}
return false;
}
#ifndef LQHELPER_H
#define LQHELPER_H
#include <vtkSMProxy.h>
/**
* @brief IsLidarProxy return true if the proxy is a LidarReader or a LidarStream
* @param proxy to test
* @return true if the proxy is a LidarReader or a LidarStream
*/
bool IsLidarProxy(vtkSMProxy * proxy);
#endif // LQHELPER_H
<RCC>
<qresource prefix="/lqResources">
<file>Icons/pqSaveState.png</file>
<file>Icons/pqLoadState.png</file>
</qresource>
</RCC>
'''
This file is a helper in the purpose of create new test data
1) It generates all vtp files (reference frames files) for the pcap you want
2) It creates the "frame_list.txt" file that contains the name of every vtp files
3) It creates the "reference-data.xml" file that contains the GetNetworkTimeToDataTime reference
** How to use this code **
You need to update all the variables that starts by UPDATE
This code has to be copied and pasted in a programmable source in LidarView
To create a programmable source : "Sources" -> "Programmable source"
Or "ctrl-space" -> "Programmable filter"
'''
from paraview import simple as sp
import os.path
# Folder where the GroundTruth folder is ALREADY created
# example of a good path : LV-Source/Plugins/PluginName/Testing/Data/Sensor/GroundTruth/'
UPDATE_GroundTruthFolder = ''
# This sensor name is only used in the name of the vtp files
UPDATE_SensorName = ''
# filename and calibration of the pcap you want to create test reference data for
# example of a good path : LV-Source/Plugins/PluginName/Testing/Data/Sensor/file.pcap/'
UPDATE_pcapFile = ''
UPDATE_calibrationFileName = ''
# Specific interpreter Name
# By default, paraview set the first interpreter in alphabetical order
# which belongs to the proxy group LidarPacketInterpreter
# If you want
UPDATE_interpreterName = ''
# Initialize the reader with the pcap and calibration files
reader = sp.LidarReader()
reader.FileName = UPDATE_pcapFile
reader.CalibrationFile = UPDATE_calibrationFileName
if UPDATE_interpreterName != "":
reader.Interpreter = UPDATE_interpreterName
reader.Interpreter.IgnoreZeroDistances = 1
reader.Interpreter.IgnoreEmptyFrames = 1
reader.Interpreter.EnableAdvancedArrays = 1
reader.ShowFirstAndLastFrame = 1
sp.Show(reader)
reader.UpdatePipeline()
reader.UpdatePipelineInformation()
# Save all vtp files in the data
saveVTPFolder = os.path.join(UPDATE_GroundTruthFolder, "{}.vtp".format(UPDATE_SensorName))
sp.SaveData(saveVTPFolder, proxy=reader, Writetimestepsasfileseries=1)
# Create the frames_list.txt files that contains the list of all vtp file name
frames_list_filename = os.path.join(UPDATE_GroundTruthFolder, "frames_list.txt")
with open(frames_list_filename, "a") as f:
f.truncate(0)
i = 0
name_i = UPDATE_SensorName + "_" + str(i) + ".vtp"
currentFile = os.path.join(UPDATE_GroundTruthFolder, name_i)
while os.path.isfile(currentFile):
f.write(name_i + "\n")
i = i + 1
name_i = UPDATE_SensorName + "_" + str(i) + ".vtp"
currentFile = os.path.join(UPDATE_GroundTruthFolder, name_i)
# Write the NetworkTime reference in the file
time = reader.GetClientSideObject().GetNetworkTimeToDataTime()
with open(UPDATE_GroundTruthFolder + "/../" + UPDATE_SensorName + "-reference-data.xml", "a") as f2:
f2.truncate(0)
contents = "<referenceData referenceNetworkTimeToDataTime=\"" + str(time) + "\">"
f2.write(contents + "\n")
f2.write("</referenceData>")