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 (8)
...@@ -14,6 +14,9 @@ lqLidarStateDialog::lqLidarStateDialog(QWidget* parent, ...@@ -14,6 +14,9 @@ lqLidarStateDialog::lqLidarStateDialog(QWidget* parent,
this->properties = propertiesVector; this->properties = propertiesVector;
this->instructions = QString(instruction.c_str()); this->instructions = QString(instruction.c_str());
this->allCheckbox = new QCheckBox(QString("Select all"));
connect(this->allCheckbox, SIGNAL(stateChanged(int)), this, SLOT(AllCheckboxStateUpdate(int)));
QVBoxLayout* vbox = new QVBoxLayout; QVBoxLayout* vbox = new QVBoxLayout;
this->CreateStateDialog(vbox); this->CreateStateDialog(vbox);
...@@ -39,9 +42,12 @@ void lqLidarStateDialog::CreateStateDialog(QVBoxLayout* vbox) ...@@ -39,9 +42,12 @@ void lqLidarStateDialog::CreateStateDialog(QVBoxLayout* vbox)
// Display a message to give a tip to the user : // Display a message to give a tip to the user :
if (!this->instructions.isEmpty()) if (!this->instructions.isEmpty())
{ {
QHBoxLayout* hboxLayout = new QHBoxLayout();
QLabel* label = new QLabel(this->instructions); QLabel* label = new QLabel(this->instructions);
label->setStyleSheet("font: italic;font-size: 12px ; color: grey"); label->setStyleSheet("font: italic;font-size: 12px ; color: grey");
vbox->addWidget(label, 0, Qt::AlignLeft); hboxLayout->addWidget(label, 0, Qt::AlignLeft);
hboxLayout->addWidget(this->allCheckbox, 0, Qt::AlignRight);
vbox->addLayout(hboxLayout);
} }
for (unsigned int i = 0; i < this->properties.size(); i++) for (unsigned int i = 0; i < this->properties.size(); i++)
...@@ -66,6 +72,51 @@ void lqLidarStateDialog::CreateStateDialog(QVBoxLayout* vbox) ...@@ -66,6 +72,51 @@ void lqLidarStateDialog::CreateStateDialog(QVBoxLayout* vbox)
hboxLayout->addWidget(currentProperty.checkbox, 0, Qt::AlignLeft); hboxLayout->addWidget(currentProperty.checkbox, 0, Qt::AlignLeft);
hboxLayout->addWidget(label, 0, Qt::AlignLeft); hboxLayout->addWidget(label, 0, Qt::AlignLeft);
vbox->addLayout(hboxLayout); vbox->addLayout(hboxLayout);
QObject::connect(
currentProperty.checkbox, SIGNAL(toggled(bool)), this, SLOT(UpdateAllCheckStates()));
} }
} }
} }
//-----------------------------------------------------------------------------
void lqLidarStateDialog::UpdateAllCheckStates()
{
size_t checked = 0;
for (auto& cb : this->properties)
{
checked += (cb.checkbox->isChecked() ? 1 : 0);
}
QSignalBlocker sblocker(this->allCheckbox);
if (checked == this->properties.size())
{
allCheckbox->setCheckState(Qt::Checked);
allCheckbox->setTristate(false);
}
else if (checked == 0)
{
allCheckbox->setCheckState(Qt::Unchecked);
allCheckbox->setTristate(false);
}
else
{
allCheckbox->setCheckState(Qt::PartiallyChecked);
}
}
//-----------------------------------------------------------------------------
void lqLidarStateDialog::AllCheckboxStateUpdate(int checkState)
{
for (auto& cb : this->properties)
{
if (!cb.isProxy())
{
QCheckBox* currentCheckbox = cb.checkbox;
QSignalBlocker sblocker(currentCheckbox);
currentCheckbox->setChecked(checkState == Qt::Checked);
}
}
this->allCheckbox->setTristate(false);
}
\ No newline at end of file
...@@ -71,10 +71,16 @@ public: ...@@ -71,10 +71,16 @@ public:
~lqLidarStateDialog() {} ~lqLidarStateDialog() {}
void CreateStateDialog(QVBoxLayout* vbox);
std::vector<propertyInfo> properties; std::vector<propertyInfo> properties;
private slots:
void UpdateAllCheckStates();
void AllCheckboxStateUpdate(int checkState);
private:
void CreateStateDialog(QVBoxLayout* vbox);
QCheckBox* allCheckbox;
QString instructions; QString instructions;
}; };
#endif // LQLIDARSTATEDIALOG_H #endif // LQLIDARSTATEDIALOG_H
...@@ -281,17 +281,17 @@ void lqSensorListWidget::onSourceRemoved(pqPipelineSource* src) ...@@ -281,17 +281,17 @@ void lqSensorListWidget::onSourceRemoved(pqPipelineSource* src)
{ {
if (IsLidarProxy(src->getProxy())) if (IsLidarProxy(src->getProxy()))
{ {
// Remove Source associated Widget // Remove and close each Source associated Widget from the sensor list
const auto it = std::remove_if(this->sensorWidgets.begin(), for (unsigned int index = 0; index < this->sensorWidgets.size(); index++)
this->sensorWidgets.end(),
[&](const lqSensorWidget* widget) { return widget->IsWidgetLidarSource(src); });
if (it == this->sensorWidgets.end())
{ {
vtkGenericWarningMacro("LidarSource removed but unaccounted for in lqSensorListWidget"); lqSensorWidget* widget = this->sensorWidgets[index];
return; // Check this is the source to be removed
if (widget->IsWidgetLidarSource(src))
{
this->sensorWidgets.erase(this->sensorWidgets.begin() + index);
widget->onClose();
}
} }
this->sensorWidgets.erase(it);
(*it)->onClose();
// Emit lidarStreamModeChanged Signal // Emit lidarStreamModeChanged Signal
if (IsLidarStreamProxy(src->getProxy()) && !isInLiveSensorMode()) if (IsLidarStreamProxy(src->getProxy()) && !isInLiveSensorMode())
......
Subproject commit dffecb3cdefd2a2f289a93c5850224611142c1ab Subproject commit 5cd7b759f961d9836d0d83430e71dd106a12b2fe
"""
Select points with a query and save all the frame of the current selection
You can download CarLoop_VLP16.pcap here: https://drive.google.com/drive/folders/1yrNUelUsjKcXdC8FH8DpXeOPTyiB_pLS
"""
import lidarview.applogic as lv
import paraview.simple as smp
################################################################################
carloop_pcap = "/home/user/data/CarLoop_VLP16.pcap"
calibration_file = "/path/to/lidarview/build/.../install/share/VLP-16.xml"
default_filename = "/home/user/data/test.csv"
################################################################################
def extractFromSelectMultipleQueries(queries = []):
""" Workaround to do a selection based on multiple queries """
selection = None
for query in queries:
smp.SelectPoints(query)
smp.Render()
tmp = smp.ExtractSelection()
# Delete intermediate selection
if selection:
smp.Delete(selection)
selection = tmp
return selection
def planeFitSelection(source):
""" Do a plane fit on the source and return a plane fitter """
# Select all point on extracted source
smp.SelectPoints("", source)
smp.Render()
# Call planeFit implementation (see Application/Ui/python/lidariew/planefit.py)
lv.planeFit()
# Return plane fit source
return smp.FindSource("PlaneFitter")
def executeProgrammableFilter(plane_fitter):
""" Create a programmable filter to perform computation on data """
prog_filter = smp.ProgrammableFilter(Input=[plane_fitter])
# Docs to use programmable filters https://docs.paraview.org/en/latest/ReferenceManual/pythonProgrammableFilter.html#
# Docs to use numpy in paraview https://docs.paraview.org/en/latest/ReferenceManual/vtkNumPyIntegration.html
prog_filter.Script = """
from paraview.vtk.numpy_interface import dataset_adapter as dsa
from paraview.vtk.numpy_interface import algorithms as algs
import numpy as np
data = inputs[0]
npts = data.RowData["npts"]
normaly = data.RowData["normaly"]
print(type(npts)) # <class 'paraview.vtk.numpy_interface.dataset_adapter.VTKArray'>
print(isinstance(npts, numpy.ndarray)) # True
approxrollangle = numpy.arcsin(normaly) * 180/3.1415 # vtk datasets are tied to numpy array
# Other treatment here
output.RowData.append(npts, "npts") # Append data in output
output.RowData.append(approxrollangle, "roll_angle") # Append data in output
"""
prog_filter.UpdatePipeline()
return prog_filter
def saveProgrammableFilterOutput(filename, prog_filter):
""" Save programmabl filter ouput to a csv """
writer = smp.CreateWriter(filename, prog_filter)
writer.Precision = 16
writer.UpdatePipeline()
smp.Delete(writer)
def planeFitAndProcessExample():
""" How to use this example """
# Open pcap
lv.openPcap(carloop_pcap, calibration_file)
# Select region on hardcoded requirement (in this case in front of lidar)
selection = extractFromSelectMultipleQueries(["azimuth > 34500", "vertical_angle < -10"])
plane_fitter = planeFitSelection(selection)
prog_filter = executeProgrammableFilter(plane_fitter)
saveProgrammableFilterOutput(default_filename, prog_filter)
# Uncomment below to execute the script directly when loaded
# planeFitAndProcessExample()
"""
Select points with a query and save all the frame of the current selection
"""
import os
import lidarview.applogic as lv
import paraview.simple as smp
import lidarviewcore.kiwiviewerExporter as kiwiExporter
################################################################################
default_filename = "/home/user/data/selected_frames.csv"
default_timesteps = range(50, 100)
################################################################################
def renderSelection(query = "intensity > 20"):
""" Selects points and render the selection using a query"""
smp.SelectPoints(query)
smp.Render()
def extractSelection():
""" Get the trailing frame with selection then
create and return the new filter 'ExtractSelection'"""
trailingFrame = smp.GetActiveSource()
extractSelection = smp.ExtractSelection(Input=trailingFrame)
return extractSelection
def saveCSVSelectionAndFrames(selection, filename = default_filename, timesteps = default_timesteps):
""" Save the selection for each frame defined in timesteps to a zip directory """
# Create a temporary directory to save all frames
tmp_dir = kiwiExporter.tempfile.mkdtemp()
basename_without_extension = os.path.splitext(os.path.basename(filename))[0]
out_dir = os.path.join(tmp_dir, basename_without_extension)
name_template = os.path.join(out_dir, basename_without_extension + " (Frame %04d).csv")
os.makedirs(out_dir)
# Create a new writer to save frames
writer = smp.CreateWriter('tmp.csv', selection)
writer.FieldAssociation = "Point Data"
writer.Precision = 16
# Get player controller to be able to search for each frame
controller = lv.getPlayerController()
for i in timesteps:
# Load each frame
controller.onSeekFrame(i)
# Name the current frame with its number
writer.FileName = name_template % i
writer.UpdatePipeline()
# Format csv file
lv.rotateCSVFile(writer.FileName)
# Clean up writer
smp.Delete(writer)
# Zip the directory with all frames and clean up temporary directory
zip_name = os.path.dirname(filename) + '/' + basename_without_extension + ".zip"
kiwiExporter.zipDir(out_dir, zip_name)
kiwiExporter.shutil.rmtree(tmp_dir)
def saveSelectPointsOnMultipleFramesExample():
""" How to use this example """
renderSelection() # This could be replaced by a manual selection
selection = extractSelection()
saveCSVSelectionAndFrames(selection)
# Uncomment below to execute the script directly when loaded
# saveSelectPointsOnMultipleFramesExample()
\ No newline at end of file