Skip to content

Commit

Permalink
Some initial work on contour propagation, also this corresponds to re…
Browse files Browse the repository at this point in the history
…lease 1.2.2
  • Loading branch information
agravgaard committed Apr 25, 2018
1 parent 14c8cb7 commit f63c488
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 8 deletions.
86 changes: 84 additions & 2 deletions Applications/CbctRecon/StructureSet.cxx
Original file line number Diff line number Diff line change
@@ -1,5 +1,87 @@
#include "StructureSet.h"
#include <itkImage.h>
#include <itkVector.h>

StructureSet::StructureSet() {}
StructureSet::StructureSet() {
m_plan_ss = new Rtss();
m_rigid_ss = new Rtss();
m_deform_ss = new Rtss();
}

StructureSet::~StructureSet() {}
StructureSet::~StructureSet() {
delete m_plan_ss;
delete m_rigid_ss;
delete m_deform_ss;
}

void StructureSet::set_planCT_ss(Rtss::Pointer &struct_set) {
m_plan_ss = struct_set.get();
}
void StructureSet::set_rigidCT_ss(Rtss::Pointer &struct_set) {
m_rigid_ss = struct_set.get();
}
void StructureSet::set_deformCT_ss(Rtss::Pointer &struct_set) {
m_deform_ss = struct_set.get();
}

// This function is very C, because Rtss is used.
void clone_rtss(const Rtss *orig_ss, Rtss *new_ss) {
auto n_structs = orig_ss->num_structures;
for (auto i = 0; i < n_structs; i++) {
new_ss->add_structure( // reallocs slist
orig_ss->slist[i]->name, orig_ss->slist[i]->color,
orig_ss->slist[i]->id, orig_ss->slist[i]->bit);
auto n_contours = orig_ss->slist[i]->num_contours;

for (auto j = 0; j < n_contours; j++) {
auto n_verts = orig_ss->slist[i]->pslist[j]->num_vertices;
new_ss->slist[i]->add_polyline(n_verts); // mallocs x, y, z

new_ss->slist[i]->pslist[j]->slice_no =
orig_ss->slist[i]->pslist[j]->slice_no;
new_ss->slist[i]->pslist[j]->ct_slice_uid =
orig_ss->slist[i]->pslist[j]->ct_slice_uid;

for (auto k = 0; k < n_verts; k++) {
new_ss->slist[i]->pslist[j]->x[k] = orig_ss->slist[i]->pslist[j]->x[k];
new_ss->slist[i]->pslist[j]->y[k] = orig_ss->slist[i]->pslist[j]->y[k];
new_ss->slist[i]->pslist[j]->z[k] = orig_ss->slist[i]->pslist[j]->z[k];
}
}
}
}

void StructureSet::transform_by_vector(const ctType struct_set,
const FloatVector vec, Rtss *out_ss) {
if (out_ss->num_structures != 0) {
out_ss->clear();
}

switch (struct_set) {
case PLAN_CT:
clone_rtss(m_plan_ss, out_ss);
break;
case RIGID_CT:
clone_rtss(m_rigid_ss, out_ss);
break;
case DEFORM_CT:
clone_rtss(m_deform_ss, out_ss);
break;
}

auto n_structs = m_plan_ss->num_structures;
#pragma omp parallel for
for (auto i = 0; i < n_structs; i++) {
Rtss_roi *cur_s = m_plan_ss->slist[i];
auto n_contours = cur_s->num_contours;
for (auto j = 0; j < n_contours; j++) {
Rtss_contour *cur_c = cur_s->pslist[j];
auto n_points = cur_c->num_vertices;
for (auto k = 0; k < n_points; k++) {
cur_c->x[k] += vec.x;
cur_c->y[k] += vec.y;
cur_c->z[k] += vec.z;
}
}
}
}
35 changes: 30 additions & 5 deletions Applications/CbctRecon/StructureSet.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,37 @@
#ifndef STRUCTURESET_H
#define STRUCTURESET_H
#include "cbctrecon.h"

class StructureSet
{
public:
StructureSet();
~StructureSet();
#include <rtss.h>
#include <rtss_contour.h>
#include <rtss_roi.h>

struct FloatVector {
float x;
float y;
float z;
};

enum ctType {
PLAN_CT = 0,
RIGID_CT = 1,
DEFORM_CT = 2,
};

class StructureSet {
public:
StructureSet();
~StructureSet();

void set_planCT_ss(Rtss::Pointer &struct_set);
void set_rigidCT_ss(Rtss::Pointer &struct_set);
void set_deformCT_ss(Rtss::Pointer &struct_set);
void transform_by_vector(ctType struct_set, FloatVector vec, Rtss *out_ss);

private:
Rtss *m_plan_ss;
Rtss *m_rigid_ss;
Rtss *m_deform_ss;
};

#endif
10 changes: 9 additions & 1 deletion Applications/CbctRecon/cbctrecon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3406,6 +3406,7 @@ QString getBowtiePath(QWidget *parent, const QDir &calDir) {
calDir.absolutePath(), "Projection (*.xim)", nullptr, nullptr);
}


std::tuple<bool, bool> CbctRecon::probeUser(const QString &guessDir) {

QString dirPath = QFileDialog::getExistingDirectory(
Expand All @@ -3414,8 +3415,15 @@ std::tuple<bool, bool> CbctRecon::probeUser(const QString &guessDir) {

bool dcm_success = false;
if (!(dirPath.length() <= 1)) {
Dcmtk_rt_study drs(dirPath.toLocal8Bit().constData());
drs.parse_directory();
Plm_image plmImg;
if (plmImg.load_native(dirPath.toLocal8Bit().constData())) {
plmImg.set(drs.get_image());

if(plmImg.have_image()){
//if (plmImg.load_native(dirPath.toLocal8Bit().constData())) {

m_structures->set_planCT_ss(drs.get_rtss());

ShortImageType::Pointer spShortImg = plmImg.itk_short();

Expand Down
2 changes: 2 additions & 0 deletions Applications/CbctRecon/cbctrecon.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
#endif

// Plastimatch
#include <dcmtk_rt_study.h>
#include <mha_io.h>
#include <nki_io.h>
#include <proj_volume.h>
Expand Down Expand Up @@ -209,6 +210,7 @@ class QStandardItemModel;
class DlgRegistration;
// class DlgHistogram;
class DlgExternalCommand;
class StructureSet;
class QTimer;
class QXmlStreamReader;

Expand Down

0 comments on commit f63c488

Please sign in to comment.