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
8 changes: 4 additions & 4 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ jobs:
strategy:
matrix:
os:
- { runner: ubuntu-latest, container: 'quay.io/pypa/manylinux_2_28_x86_64', name: linux }
- { runner: windows-latest, container: '', name: windows }
- { runner: macos-latest, container: '', name: mac }
- { runner: ubuntu-24.04, container: 'quay.io/pypa/manylinux_2_28_x86_64', name: linux }
- { runner: windows-2022, container: '', name: windows }
- { runner: macos-14, container: '', name: mac }
container: ${{ matrix.os.container }}
steps:
- name: Checkout repository
Expand Down Expand Up @@ -107,7 +107,7 @@ jobs:

mkdir build
cd build
cmake $ARCH_FLAGS -DCMAKE_BUILD_TYPE=Release -DBUILD_C_BINDS=ON -DWITH_NATIVE=OFF -DWITH_DICOM=OFF -DWITH_MULTI_THREADING=ON -DWITH_EMBEDDED_DB=OFF ..
cmake $ARCH_FLAGS -DCMAKE_BUILD_TYPE=Release -DBUILD_C_BINDS=ON -DWITH_NATIVE=OFF -DWITH_DICOM=ON -DWITH_EMBEDDED_DB=OFF ..
cmake --build . --target install --config Release -j 4
working-directory: ${{ github.workspace }}/src/build/PenRed/src

Expand Down
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ if(BUILD_VIEW_SHARED_LIB)
SOURCE_DIR "${CMAKE_SOURCE_DIR}/PenRed/repo"
BINARY_DIR "${CMAKE_SOURCE_DIR}/PenRed"
SOURCE_SUBDIR "src"
CMAKE_ARGS -DBUILD_C_BINDS=ON -DWITH_NATIVE=ON -DWITH_DICOM=OFF -DWITH_MULTI_THREADING=ON -DWITH_MPI=OFF -DWITH_LB=OFF -DDEVELOPMENT_WARNINGS=OFF
CMAKE_ARGS -DBUILD_C_BINDS=ON -DWITH_NATIVE=ON -DWITH_DICOM=OFF -DWITH_MPI=OFF -DWITH_LB=OFF -DDEVELOPMENT_WARNINGS=OFF
)

install(
Expand Down
97 changes: 93 additions & 4 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,18 @@ MainWindow::MainWindow(QWidget *parent)
penRedViewer(nullptr),
constructViewer(nullptr),
destroyViewer(nullptr),
width3D(400), height3D(400), pixelSize3D(0.1)
width3D(400), height3D(400), pixelSize3D(0.1),
playing(false)
{
//Init viewer colors
viewer::resetColors();

//Create the animation timer
animationTimer = std::make_shared<QTimer>(this);

animationTimer->setTimerType(Qt::PreciseTimer);
connect(animationTimer.get(), &QTimer::timeout, this, &MainWindow::updateTime);

setWindowTitle("PenRed Geometry Viewer");

ui->setupUi(this);
Expand All @@ -30,23 +37,31 @@ MainWindow::MainWindow(QWidget *parent)
<< QUrl::fromLocalFile(QStandardPaths::standardLocations(QStandardPaths::PicturesLocation).first())
<< QUrl::fromLocalFile(QStandardPaths::standardLocations(QStandardPaths::HomeLocation).first());


// Get home directory path
QString homeDir = QStandardPaths::standardLocations(QStandardPaths::HomeLocation).first();

saveDialog.setDirectory(homeDir); // Start in home directory
saveDialog.setSidebarUrls(urls);
saveDialog.setFileMode(QFileDialog::AnyFile);
saveDialog.setAcceptMode(QFileDialog::AcceptSave);
connect(&saveDialog, &QFileDialog::fileSelected, this, &MainWindow::on_saveImage);

//Configure load dialogs

loadConfigDialog.setDirectory(homeDir); // Start in home directory
loadConfigDialog.setSidebarUrls(urls);
loadConfigDialog.setFileMode(QFileDialog::ExistingFile);
loadConfigDialog.setAcceptMode(QFileDialog::AcceptOpen);
connect(&loadConfigDialog, &QFileDialog::fileSelected, this, &MainWindow::on_loadConfig);

loadQuadricDialog.setDirectory(homeDir); // Start in home directory
loadQuadricDialog.setSidebarUrls(urls);
loadQuadricDialog.setFileMode(QFileDialog::ExistingFile);
loadQuadricDialog.setAcceptMode(QFileDialog::AcceptOpen);
connect(&loadQuadricDialog, &QFileDialog::fileSelected, this, &MainWindow::on_loadQuadric);

loadMeshDialog.setDirectory(homeDir); // Start in home directory
loadMeshDialog.setSidebarUrls(urls);
loadMeshDialog.setFileMode(QFileDialog::ExistingFile);
loadMeshDialog.setAcceptMode(QFileDialog::AcceptOpen);
Expand Down Expand Up @@ -366,11 +381,26 @@ void MainWindow::on_loadConfig(const QString &file){
//Initialize the viewer in another thread
QFuture<int> future = QtConcurrent::run([this, file]{

qInfo() << "Selected configuration file " << file << "\n";
QFileInfo fileInfo(file);
QString directoryPath = fileInfo.absolutePath();
QString originalWorkingDir = QDir::currentPath();

qInfo() << "Changing directory to " << directoryPath << "\n";

// Qt handles the platform-specific implementation
if (!QDir::setCurrent(directoryPath)) {
qWarning() << "Could not change to directory:" << directoryPath << "\n";
}

qInfo() << "Loading configuration file";

int err = penRedViewer->init(file.toStdString().c_str());
if(err != 0){
printf("Error loading the geometry\n");
fflush(stdout);
qWarning() << "Error loading the geometry";
}
qInfo() << "Returning to original directory " << originalWorkingDir << "\n";
QDir::setCurrent(originalWorkingDir);
return err;
});

Expand Down Expand Up @@ -549,6 +579,13 @@ void MainWindow::setActiveViewer(unsigned index){

if(viewersArray[activeViewer] != nullptr)
viewersArray[activeViewer]->setStyleSheet("border: none");
if(activeViewer != index){
stopAnimation();
ui->playButton->setIcon(QIcon::fromTheme("media-playback-start"));
if (ui->playButton->icon().isNull()) {
ui->playButton->setIcon(style()->standardIcon(QStyle::SP_MediaPlay));
}
}
activeViewer = index;
viewersArray[activeViewer]->setStyleSheet("border: 5px outset rgb(0,128,255); border-radius: 4px;");

Expand Down Expand Up @@ -586,6 +623,9 @@ void MainWindow::updateViewerInfo(){
ui->lookY->setText(QString::number(pviewer->readCamera3DY(), 'e', 5));
ui->lookZ->setText(QString::number(pviewer->readCamera3DZ(), 'e', 5));

ui->Tedit->setValue(pviewer->readTime());
ui->TStepEdit->setValue(pviewer->readDTime());

updateKey();
}

Expand Down Expand Up @@ -656,6 +696,55 @@ void MainWindow::on_Zedit_editingFinished()
}
}

void MainWindow::on_Tedit_valueChanged(double arg1){
if(viewersArray[activeViewer] != nullptr){
viewersArray[activeViewer]->setTime(arg1);
updateKey();
}
}

void MainWindow::on_playButton_released(){
if(viewersArray[activeViewer] != nullptr){
toggleAnimation();
updateKey();
}
}

void MainWindow::updateTime() {
if(viewersArray[activeViewer] != nullptr){
if(isPlaying()){
viewersArray[activeViewer]->increaseTime();
ui->Tedit->setValue(viewersArray[activeViewer]->readTime());
}
}
}

void MainWindow::toggleAnimation(){
if(isPlaying()){
animationTimer->stop();
ui->playButton->setIcon(QIcon::fromTheme("media-playback-start"));
if (ui->playButton->icon().isNull()) {
ui->playButton->setIcon(style()->standardIcon(QStyle::SP_MediaPlay));
}
} else {
animationTimer->start(500); //Update every 500 ms
ui->playButton->setIcon(QIcon::fromTheme("media-playback-pause"));

// Fallback if theme icon not available
if(ui->playButton->icon().isNull()) {
ui->playButton->setIcon(style()->standardIcon(QStyle::SP_MediaPause));
}
}
playing = !playing;
}

void MainWindow::on_TStepEdit_valueChanged(double arg1){
if(viewersArray[activeViewer] != nullptr){
viewersArray[activeViewer]->setDTime(arg1);
updateKey();
}
}

void MainWindow::on_matBodyViewButton_released()
{
if(viewersArray[activeViewer] != nullptr){
Expand Down Expand Up @@ -748,7 +837,7 @@ void MainWindow::on_testButton_released()
QElapsedTimer timer;
timer.start();

std::vector<geoError> errors = viewersArray[activeViewer]->test();
std::vector<penred::geometry::viewError> errors = viewersArray[activeViewer]->test();

qint64 elapsed = timer.elapsed();

Expand Down
27 changes: 23 additions & 4 deletions src/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ private slots:

void on_Zedit_editingFinished();

void on_Tedit_valueChanged(double arg1);

void on_TStepEdit_valueChanged(double arg1);

void on_playButton_released();

void on_matBodyViewButton_released();

void on_perspectiveSelector_currentIndexChanged(int index);
Expand Down Expand Up @@ -116,11 +122,11 @@ private slots:
private:

std::array<std::vector<uchar>,maxViewers> buffers;
std::array<std::vector<unsigned char>,maxViewers> matImages;
std::array<std::vector<unsigned int>,maxViewers> matImages;
std::array<std::vector<unsigned int>,maxViewers> bodyImages;
std::array<std::vector<float>,maxViewers> distances;

pen_geoViewInterface* penRedViewer;
penred::geometry::ViewerInterface* penRedViewer;
QLibrary viewerLib;

QFileDialog saveDialog;
Expand All @@ -132,9 +138,9 @@ private slots:
QVBoxLayout* colorListLayout;
QColorDialog* selectColorDialog;

typedef pen_geoViewInterface* (*viewerConstructor)();
typedef penred::geometry::ViewerInterface* (*viewerConstructor)();
viewerConstructor constructViewer;
typedef void (*viewerDestructor)(pen_geoViewInterface*);
typedef void (*viewerDestructor)(penred::geometry::ViewerInterface*);
viewerDestructor destroyViewer;

unsigned nViewers;
Expand All @@ -143,6 +149,10 @@ private slots:
unsigned width3D, height3D;
double pixelSize3D;

std::shared_ptr<QTimer> animationTimer;
bool playing;


Ui::MainWindow *ui;

void setActiveViewer(unsigned index);
Expand All @@ -166,5 +176,14 @@ private slots:
void loadViewerColors(const QString &file);
void saveViewerColors(const QString &file);

void updateTime();
void toggleAnimation();
inline bool isPlaying(){ return playing; }
inline void stopAnimation(){
if(isPlaying()){
toggleAnimation();
}
}

};
#endif // MAINWINDOW_H
Loading
Loading