+ bool verbose = args_info.verbose_flag;
+
+ std::string reference_filename(args_info.reference_arg);
+ std::string target_filename(args_info.target_arg);
+ std::string gamma_filename(args_info.output_arg);
+ double space_margin = args_info.spatial_margin_arg;
+ double dose_rel_margin = args_info.relative_dose_margin_arg;
+ double dose_margin = args_info.absolute_dose_margin_arg;
+ bool use_dose_margin = args_info.absolute_dose_margin_given;
+
+ if (verbose) {
+ cout << "reference_filename=" << reference_filename << endl;
+ cout << "target_filename=" << target_filename << endl;
+ cout << "gamma_filename=" << gamma_filename << endl;
+ cout << "space_margin=" << space_margin << endl;
+ if (use_dose_margin) cout << "dose_margin=" << dose_margin << endl;
+ else cout << "dose_rel_margin=" << dose_rel_margin << endl;
+ }
+
+ // load reference
+ vtkImageData* reference = loadImage(reference_filename);
+ assert(reference);
+
+ // translate target with arguments values
+ // reference is translated instead of target so that the output space stay the same as target
+ {
+ double reference_origin[3];
+ reference->GetOrigin(reference_origin);
+ reference_origin[0] -= args_info.translation_x_arg;
+ reference_origin[1] -= args_info.translation_y_arg;
+ reference_origin[2] -= args_info.translation_z_arg;
+ reference->SetOrigin(reference_origin);
+ }
+
+ // intensity normalisation
+ if (!use_dose_margin) {
+ dose_margin = getMaximum(reference)*dose_rel_margin;
+ if (verbose) cout << "dose_margin=" << dose_margin << endl;
+ }
+
+ // build surface
+ vtkPolyData *data = buildPlane(reference,space_margin,dose_margin);
+ reference->Delete();
+
+ vtkAbstractCellLocator *locator = vtkCellLocator::New();
+ locator->SetDataSet(data);
+ DD("here");
+ // data->Delete();
+ locator->CacheCellBoundsOn();
+ locator->AutomaticOn();
+ DD("BuildLocator");
+ locator->BuildLocator();
+ DD("end BuildLocator");
+
+ // load target
+ vtkImageData* target = loadImage(target_filename);
+ assert(target);
+
+
+ // allocate output
+ OutputImageType::Pointer output = OutputImageType::New();
+ {
+ OutputImageType::SizeType::SizeValueType output_array_size[2];
+ output_array_size[0] = target->GetDimensions()[0];
+ output_array_size[1] = target->GetDimensions()[1];
+ OutputImageType::SizeType output_size;
+ output_size.SetSize(output_array_size);
+ output->SetRegions(OutputImageType::RegionType(output_size));
+ output->SetOrigin(target->GetOrigin());
+ output->SetSpacing(target->GetSpacing());
+ output->Allocate();
+ }
+
+ // fill output
+ unsigned long kk = 0;
+ unsigned long over_one = 0;
+ OutputImageIterator iter(output,output->GetLargestPossibleRegion());
+ iter.GoToBegin();
+ DD("loop");
+ while (!iter.IsAtEnd()) {
+ double *point = target->GetPoint(kk);
+ double value = target->GetPointData()->GetScalars()->GetTuple1(kk);
+ assert(value>=0);
+ assert(point[2]==0);
+ point[2] = value;
+
+ point[0] /= space_margin;
+ point[1] /= space_margin;
+ point[2] /= dose_margin;
+
+ double closest_point[3] = {0,0,0};
+ vtkIdType cell_id = 0;
+ int foo = 0;
+ double squared_distance = 0;
+
+ locator->FindClosestPoint(point,closest_point,cell_id,foo,squared_distance);
+ double distance = sqrt(squared_distance);
+ iter.Set(distance);
+
+ if (distance>1) over_one++;
+ kk++;
+ ++iter;
+ }
+
+ if (verbose) {
+ cout << "total=" << kk << endl;
+ cout << "over_one=" << over_one << endl;
+ cout << "ratio=" << static_cast<float>(over_one)/kk << endl;
+ }
+
+ locator->Delete();
+ target->Delete();
+
+ saveImage(output,gamma_filename);
+
+ return 0;
+}