Commit 79dfa26c authored by Emmanuel Promayon's avatar Emmanuel Promayon
Browse files

FIXED more consistant ERROR log entry + various little bugs or code formatting

parent efda4f66
......@@ -66,7 +66,7 @@ DicomComponent::DicomComponent(DicomSerie* dicomSerie) throw(AbortException) : I
ippSorter.SetComputeZSpacing(true);
ippSorter.SetZSpacingTolerance(0.001);
if (!ippSorter.Sort(stdFileNames)) {
CAMITK_ERROR("DicomComponent::DicomSerieComponent(..): IPPSorter sorting failed. Try to adjust Z spacing tolerance.")
CAMITK_ERROR("IPPSorter sorting failed. Try to adjust Z spacing tolerance.")
files = stdFileNames;
zSpacing = DicomParser::getZSpacing(files);
}
......@@ -172,15 +172,14 @@ camitk::ImageOrientationHelper::PossibleImageOrientations DicomComponent::readDi
gdcm::Scanner scanner;
gdcm::Tag iopTag = gdcm::Tag(0x0020, 0x0037);
scanner.AddTag(iopTag);
if (!scanner.Scan(fileNames)) { // Definitively, scan should never failed, since DicomParser::parseDirectory() has already filter files.
CAMITK_ERROR("DicomComponent::readDirectCosinesAngle(..): scan failed looking for tag (0x0020, 0x0037) Image Orientation Patient");
}
// Scan should never failed, since DicomParser::parseDirectory() has already filter files.
CAMITK_ERROR_IF((!scanner.Scan(fileNames)),"Scan failed looking for tag (0x0020, 0x0037) Image Orientation Patient.")
// Check value tag exists
gdcm::Scanner::TagToValue const& ttv = scanner.GetMapping(fileNames[0].c_str());
gdcm::Scanner::TagToValue::const_iterator it = ttv.find(iopTag);
if (!(it != ttv.end())) {
CAMITK_WARNING("DicomComponent::readDirectCosinesAngle(..): no tag (0x0020, 0x0037) Image Orientation Patient found on image " + QString::fromStdString(fileNames[0]));
CAMITK_WARNING("No tag (0x0020, 0x0037) Image Orientation Patient found on image \"" + QString::fromStdString(fileNames[0]) + "\"");
return ImageOrientationHelper::UNKNOWN;
}
......
......@@ -225,7 +225,7 @@ double DicomParser::getZSpacing(const std::vector<std::string>& serieFileNames)
std::string file = serieFileNames.at(0);
const char* value = scanner.GetValue(file.c_str(), zSpacingTag);
if (!value) {
CAMITK_BASIC_ERROR("DicomParser::getZSpacing(..): no Z spacing found on image: " + QString::fromStdString(serieFileNames.at(0)));
CAMITK_BASIC_ERROR("No Z spacing found on image: " + QString::fromStdString(serieFileNames.at(0)));
return 1.0;
}
return atof(value);
......
......@@ -115,7 +115,9 @@ vtkSmartPointer<vtkImageData> ItkImageComponent::readVolume(const QString& filen
// set the original slices. Other orientation are build when/if required only.
}
catch (itk::ExceptionObject& err ) {
CAMITK_ERROR(tr("ITK exception caught while reading the volume):\n") + err.what())
std::stringstream buffer;
err.Print(buffer);
CAMITK_ERROR(tr("ITK exception caught while reading the volume):\n") + err.what() + "\n" + QString(buffer.str().c_str()) + "\n")
return NULL;
}
......
......@@ -282,7 +282,9 @@ template<class ImageType> bool ItkImageComponentExtension::saveImage(ImageCompon
writer->Update();
}
catch (const itk::ExceptionObject& err ) {
CAMITK_BASIC_ERROR("ItkImageComponentExtension::saveImage(): saving Error: problem occurs while saving file:" + filename + ": ITK Exception: " + err.what());
std::stringstream buffer;
err.Print(buffer);
CAMITK_BASIC_ERROR("ItkImageComponentExtension::saveImage(): saving Error: problem occurs while saving file:" + filename + ": ITK Exception: " + err.what() + "\n" + QString(buffer.str().c_str()) + "\n");
return false;
}
......
......@@ -73,7 +73,12 @@ Action::ApplyStatus CloseAction::apply() {
it++;
}
// CCC Exception: just a trace message as the user voluntarily aborted the action
CAMITK_TRACE_IF((it != allTopLevel.constEnd()), "Canceled by user. Action Aborted.")
return (it == allTopLevel.constEnd()) ? SUCCESS : ABORTED;
if (it == allTopLevel.constEnd()) {
return SUCCESS;
}
else {
// CCC Exception: just a trace message as the user voluntarily aborted the action
CAMITK_TRACE("Canceled by user. Action Aborted.")
return ABORTED;
}
}
......@@ -35,20 +35,20 @@
using namespace camitk;
// --------------- constructor -------------------
OpenAction::OpenAction (ActionExtension* extension) : Action (extension) {
OpenAction::OpenAction(ActionExtension* extension) : Action(extension) {
// Setting name, description and input component
setName ("Open");
setEmbedded (false);
setDescription (tr("Open data (component) from a file"));
setComponent ("");
setName("Open");
setEmbedded(false);
setDescription(tr("Open data (component) from a file"));
setComponent("");
// Setting classification family and tags
setFamily ("Application");
addTag (tr("Open"));
setFamily("Application");
addTag(tr("Open"));
// add a shortcut
setIcon(QPixmap(":/fileOpen"));
getQAction()->setShortcut( QKeySequence::Open );
getQAction()->setShortcut(QKeySequence::Open);
getQAction()->setShortcutContext(Qt::ApplicationShortcut);
}
......@@ -70,15 +70,15 @@ Action::ApplyStatus OpenAction::apply() {
QString allKnownFiles; //example: (*.xml *.vtk *.wrl)
// first item = all known files
filter += QString ("All known files (*.") + ExtensionManager::getFileExtensions().join(" *.") + ");;";
filter += QString("All known files (*.") + ExtensionManager::getFileExtensions().join(" *.") + ");;";
// add the extension of loaded and valid plugins
foreach(ComponentExtension * ext, ExtensionManager::getComponentExtensionsList()) {
foreach (ComponentExtension* ext, ExtensionManager::getComponentExtensionsList()) {
filter += ext->getName() + " (*." + ext->getFileExtensions().join(" *.") + ");;";
}
// Open more than one file
QStringList files = QFileDialog::getOpenFileNames (NULL, tr("Select One or More Files to Open"), Application::getLastUsedDirectory().absolutePath(), filter);
QStringList files = QFileDialog::getOpenFileNames(NULL, tr("Select One or More Files to Open"), Application::getLastUsedDirectory().absolutePath(), filter);
if (!files.isEmpty()) {
QStringList listOfFiles = files; // as stated by the Qt doc (although without further information): "If you want to iterate over the list of files, you should iterate over a copy."
......@@ -87,17 +87,17 @@ Action::ApplyStatus OpenAction::apply() {
++fileIterator;
}
if (fileIterator == listOfFiles.constEnd()) {
Application::showStatusBarMessage(tr ("All files opened."));
Application::showStatusBarMessage(tr("All files opened."));
return SUCCESS;
}
else {
Application::showStatusBarMessage(tr ("Error opening files: ") + (*fileIterator));
CAMITK_ERROR("OpenAction::apply(): some files can not be opened. Action failed.")
Application::showStatusBarMessage(tr("Error opening files: ") + (*fileIterator));
CAMITK_ERROR("Some files can not be opened. Action failed.")
return ERROR;
}
}
else {
Application::showStatusBarMessage(tr ("Open aborted."));
Application::showStatusBarMessage(tr("Open aborted."));
// CCC Exception: just a trace message as the user voluntarily aborted the action
CAMITK_TRACE("A file is required. Action aborted.")
return ABORTED;
......
......@@ -26,6 +26,7 @@
//-- CamiTK
#include <Application.h>
#include <Component.h>
#include <Log.h>
#include "RemoveLastInstanciatedAction.h"
......@@ -71,5 +72,7 @@ Action::ApplyStatus RemoveLastInstanciatedAction::apply() {
Application::refresh();
return SUCCESS;
}
CAMITK_ERROR("No component to delete.")
return ERROR;
}
......@@ -25,6 +25,7 @@
#include "SaveAction.h"
#include <Application.h>
#include <Log.h>
using namespace camitk;
......@@ -72,5 +73,11 @@ Action::ApplyStatus SaveAction::apply() {
++it;
}
return (it == allTopLevel.constEnd()) ? SUCCESS : ERROR;
if (it == allTopLevel.constEnd()) {
return SUCCESS;
}
else {
CAMITK_WARNING("Canceled. Action Aborted.")
return ABORTED;
}
}
......@@ -29,6 +29,7 @@
#include <ImageComponentExtension.h>
#include <MeshComponent.h>
#include <MeshComponentExtension.h>
#include <Log.h>
#include <QFileDialog>
......@@ -69,9 +70,14 @@ Action::ApplyStatus SaveAllAction::apply() {
++it;
}
return (it == Application::getTopLevelComponents().constEnd()) ? SUCCESS : ERROR;
Application::showStatusBarMessage( tr ( "Ready." ) );
return ERROR;
if (it == Application::getTopLevelComponents().constEnd()) {
return SUCCESS;
}
else {
CAMITK_WARNING("Canceled. Action Aborted.")
return ABORTED;
}
}
......@@ -194,7 +194,8 @@ Action::ApplyStatus SaveAsAction::apply() {
}
else {
comp->setFileName(compfileName);
return ERROR;
CAMITK_WARNING("Canceled. Action Aborted.")
return ABORTED;
}
}
else {
......@@ -204,6 +205,5 @@ Action::ApplyStatus SaveAsAction::apply() {
return ABORTED;
}
return ERROR;
}
......@@ -26,7 +26,7 @@
// CamiTK
#include <Application.h>
#include <Component.h>
#include <Log.h>
using namespace camitk;
......@@ -55,10 +55,12 @@ QWidget* SelectLastInstanciatedAction::getWidget() {
// --------------- apply -------------------
Action::ApplyStatus SelectLastInstanciatedAction::apply() {
const ComponentList& allComponent = Application::getAllComponents();
// unselect all others top level components
for (int i = 0; i < allComponent.size(); i++) {
allComponent.at(i)->getTopLevelComponent()->setSelected(false);
}
// select the last instanciated component
if (!allComponent.isEmpty()) {
Component* lastComponent = allComponent.last();
......@@ -73,6 +75,9 @@ Action::ApplyStatus SelectLastInstanciatedAction::apply() {
Application::refresh();
return SUCCESS;
}
return ERROR;
else {
CAMITK_ERROR("No top-level component instanciated. Nothing to select.")
return ERROR;
}
}
......@@ -25,9 +25,8 @@
#include "SetPathToTestData.h"
// CamiTK
#include <Application.h>
#include <Component.h>
#include <Core.h>
#include <Log.h>
using namespace camitk;
......@@ -61,6 +60,7 @@ Action::ApplyStatus SetPathToTestData::apply() {
return SUCCESS;
}
else {
CAMITK_ERROR("Can not set current working directory to path \"" + Core::getTestDataDir() + "\"")
return ERROR;
}
}
......
......@@ -365,10 +365,15 @@ void ImageLutWidget::draw () {
//---------------------- fillHistogramTable ------------------------
template<class DATATYPE>
void ImageLutWidget::fillHistogramTable(DATATYPE* data, unsigned int dataDim, DATATYPE minVal, DATATYPE maxVal) {
if (((DATATYPE)nbHistoBins) == 0) {
CAMITK_ERROR("Number of bins is equals to zero.");
}
// scale factor from [min,max] to [0..nbHistoBins]
DATATYPE intervalLength = (DATATYPE) ((maxVal - minVal) / (DATATYPE)nbHistoBins);
if ( intervalLength ) {
if ( intervalLength != 0 ) {
//-- build histogram
for (unsigned int i = 0; i < dataDim; i++ ) {
// Find the corresponding interval index
......@@ -386,8 +391,7 @@ void ImageLutWidget::fillHistogramTable(DATATYPE* data, unsigned int dataDim, DA
}
}
else {
QString msg = "Division by zero";
CAMITK_ERROR("ImageLutWidget::fillHistogramTable: " + msg);
CAMITK_ERROR("Not enough levels in the image, level in [" + QString::number(minVal) + "," + QString::number(maxVal) + "]")
}
}
......
......@@ -41,13 +41,14 @@
using namespace camitk;
// ---------------------- Constructor ----------------------------
// ---------------------- Constructor ----------------------
VolumeRenderingWidget::VolumeRenderingWidget(VolumeRenderingAction* dad, QWidget* parent) : QWidget( parent) {
this->dad = dad;
myImage = NULL;
ui.setupUi(this);
}
// ---------------------- Destructor ----------------------
VolumeRenderingWidget::~VolumeRenderingWidget() {
// Remove all existing colors
QList<ColorPointWidget*>::const_iterator colorIt;
......@@ -58,7 +59,6 @@ VolumeRenderingWidget::~VolumeRenderingWidget() {
}
colorPoints.clear();
// Remove all existing transparencies
QList<TransparencyPointWidget*>::const_iterator transIt;
for (transIt = transparencies.begin(); transIt != transparencies.end(); transIt++) {
......@@ -77,6 +77,7 @@ VolumeRenderingWidget::~VolumeRenderingWidget() {
gradientOpacities.clear();
}
// ---------------------- updateImage ----------------------
void VolumeRenderingWidget::updateImage(ImageComponent* comp) {
if (myImage != comp) {
myImage = comp;
......@@ -87,7 +88,7 @@ void VolumeRenderingWidget::updateImage(ImageComponent* comp) {
}
}
// -------------------------- Colors
// ---------------------- addColor ----------------------
void VolumeRenderingWidget::addColor() {
ColorPointWidget* point = new ColorPointWidget(this);
this->colorPoints.push_back(point);
......@@ -100,12 +101,14 @@ void VolumeRenderingWidget::addColor(int grayLevel, QColor color) {
ui.colorsLayout->addWidget(point);
}
// ---------------------- removeColorPoint ----------------------
void VolumeRenderingWidget::removeColorPoint(ColorPointWidget* point) {
ui.colorsLayout->removeWidget(point);
this->colorPoints.removeAt(colorPoints.indexOf(point));
delete point;
}
// ---------------------- setDefaultColors ----------------------
void VolumeRenderingWidget::setDefaultColors(QMap<int, QColor> defaultColors) {
// Remove all existing colors
QList<ColorPointWidget*>::const_iterator colorIt;
......@@ -125,6 +128,7 @@ void VolumeRenderingWidget::setDefaultColors(QMap<int, QColor> defaultColors) {
}
}
// ---------------------- getColorPoints ----------------------
QMap<int, QColor> VolumeRenderingWidget::getColorPoints() {
QMap<int, QColor> colors;
QList<ColorPointWidget*>::const_iterator it;
......@@ -138,8 +142,7 @@ QMap<int, QColor> VolumeRenderingWidget::getColorPoints() {
return colors;
}
// ----------------------- Transparency
// ---------------------- addTransparency ----------------------
void VolumeRenderingWidget::addTransparency() {
TransparencyPointWidget* point = new TransparencyPointWidget(this);
this->transparencies.push_back(point);
......@@ -152,12 +155,14 @@ void VolumeRenderingWidget::addTransparency(int grayLevel, double transparency)
ui.transparenciesLayout->addWidget(point);
}
// ---------------------- removeTransparencyPoint ----------------------
void VolumeRenderingWidget::removeTransparencyPoint(TransparencyPointWidget* point) {
ui.transparenciesLayout->removeWidget(point);
this->transparencies.removeAt(transparencies.indexOf(point));
delete point;
}
// ---------------------- setDefaultTransparencies ----------------------
void VolumeRenderingWidget::setDefaultTransparencies(QMap<int, double> defaultTransparencies) {
// Remove all existing transparencies
QList<TransparencyPointWidget*>::const_iterator transIt;
......@@ -177,6 +182,7 @@ void VolumeRenderingWidget::setDefaultTransparencies(QMap<int, double> defaultTr
}
}
// ---------------------- getTransparencyPoints ----------------------
QMap<int, double> VolumeRenderingWidget::getTransparencyPoints() {
QMap<int, double> transPoints;
QList<TransparencyPointWidget*>::const_iterator it;
......@@ -190,8 +196,7 @@ QMap<int, double> VolumeRenderingWidget::getTransparencyPoints() {
return transPoints;
}
// ----------------------- Gradient Opacity
// ---------------------- addGradientOpacity ----------------------
void VolumeRenderingWidget::addGradientOpacity() {
GradientOpacityWidget* point = new GradientOpacityWidget(this);
this->gradientOpacities.push_back(point);
......@@ -204,12 +209,14 @@ void VolumeRenderingWidget::addGradientOpacity(int grayLevel, double opacity) {
ui.gradientOpacitiesLayout->addWidget(point);
}
// ---------------------- removeOpacityPoint ----------------------
void VolumeRenderingWidget::removeOpacityPoint(GradientOpacityWidget* point) {
ui.gradientOpacitiesLayout->removeWidget(point);
this->gradientOpacities.removeAt(gradientOpacities.indexOf(point));
delete point;
}
// ---------------------- setDefaultOpacities ----------------------
void VolumeRenderingWidget::setDefaultOpacities(QMap<int, double> defaultOpacities) {
// Remove all existing colors
QList<GradientOpacityWidget*>::const_iterator gradientIt;
......@@ -229,6 +236,7 @@ void VolumeRenderingWidget::setDefaultOpacities(QMap<int, double> defaultOpaciti
}
}
// ---------------------- getOpacityPoints ----------------------
QMap<int, double> VolumeRenderingWidget::getOpacityPoints() {
QMap<int, double> opacities;
QList<GradientOpacityWidget*>::const_iterator it;
......@@ -243,55 +251,57 @@ QMap<int, double> VolumeRenderingWidget::getOpacityPoints() {
}
// ------------------------ Lights
// ---------------------- setAmbiant ----------------------
void VolumeRenderingWidget::setAmbiant(double ambiant) {
ui.ambiantSpinBox->setValue(ambiant);
}
// ---------------------- getAmbiant ----------------------
double VolumeRenderingWidget::getAmbiant() {
return ui.ambiantSpinBox->value();
}
// ---------------------- setDiffuse ----------------------
void VolumeRenderingWidget::setDiffuse(double diffuse) {
ui.diffuseSpinBox->setValue(diffuse);
}
// ---------------------- getDiffuse ----------------------
double VolumeRenderingWidget::getDiffuse() {
return ui.diffuseSpinBox->value();
}
// ---------------------- setSpecular ----------------------
void VolumeRenderingWidget::setSpecular(double specular) {
ui.specularSpinBox->setValue(specular);
}
// ---------------------- getSpecular ----------------------
double VolumeRenderingWidget::getSpecular() {
return ui.specularSpinBox->value();
}
// ---------------------- load ----------------------
void VolumeRenderingWidget::load(QString filename) {
QString msg;
QDomDocument doc;
QFile file(filename);
if (!file.open(QIODevice::ReadOnly)) {
msg = tr("File not found: the file ") + filename + tr(" was not found");
CAMITK_ERROR("VolumeRenderingWidget::load: " + msg);
msg = tr("Error: cannot fine file ") + filename + tr(" sorry...\n");
CAMITK_ERROR(tr("File not found: \"") + filename + "\"");
return;
}
if (!doc.setContent(&file)) {
msg = tr("File ") + filename + tr(" have no valid root (not a valid XML file format).\n");
file.close();
CAMITK_ERROR("VolumeRenderingWidget::load: " + msg);
CAMITK_ERROR(tr("File \"") + filename + tr("\" have no valid root (not a well formed XML document)."));
return;
}
QString rootName = doc.documentElement().nodeName();
if (rootName != QString("vrColorMap")) {
file.close();
msg = tr("File ") + filename + tr(" is not in the right xml file format.\n");
CAMITK_ERROR("VolumeRenderingWidget::load: " + msg);
CAMITK_ERROR(tr("File \"") + filename + tr("\" is not a valid XML document (expecting <vrColorMap> as root element)"));
return;
}
......@@ -361,21 +371,12 @@ void VolumeRenderingWidget::load(QString filename) {
}
// ------------------------- Refresh
void VolumeRenderingWidget::refreshVolumeRendering() {
VolumeRenderingAction* dadVR = dynamic_cast<VolumeRenderingAction*> (dad);
if (dadVR) {
dadVR->createVolumeRendering(myImage);
}
}
void VolumeRenderingWidget::load() {
QString filename = QFileDialog::getOpenFileName(this, tr("Open Volume Rendering Colormap"));
load(filename);
}
// ---------------------- save ----------------------
void VolumeRenderingWidget::save() {
QString filename = QFileDialog::getSaveFileName(this, tr("Save Volume Rendering Colormap"));
......@@ -460,20 +461,28 @@ void VolumeRenderingWidget::save() {
file.close();
}
else {
msg = tr("File not found: the file ") + filename + tr(" was not found");
CAMITK_ERROR("VolumeRenderingWidget::save: " + msg);
msg = tr("Error: cannot fine file ") + filename + tr(" sorry...\n");
CAMITK_ERROR(tr("File not found: \"") + filename + "\"");
return;
}
}
// ---------------------- refreshVolumeRendering ----------------------
void VolumeRenderingWidget::refreshVolumeRendering() {
VolumeRenderingAction* dadVR = dynamic_cast<VolumeRenderingAction*> (dad);
if (dadVR) {
dadVR->createVolumeRendering(myImage);
}
}
// ---------------------- ambiantLightSliderChanged ----------------------
void VolumeRenderingWidget::ambiantLightSliderChanged(int value) {
double val = value / 100.0;
ui.ambiantSpinBox->setValue(val);
}
// ---------------------- ambiantLightSpinBoxChanged ----------------------
void VolumeRenderingWidget::ambiantLightSpinBoxChanged(double value) {
int val = (int) (value * 100);
ui.ambiantSlider->blockSignals(true);
......@@ -481,11 +490,13 @@ void VolumeRenderingWidget::ambiantLightSpinBoxChanged(double value) {
ui.ambiantSlider->blockSignals(false);
}
// ---------------------- diffuseLightSliderChanged ----------------------
void VolumeRenderingWidget::diffuseLightSliderChanged(int value) {
double val = value / 100.0;
ui.diffuseSpinBox->setValue(val);
}
// ---------------------- diffuseLightSpinBoxChanged ----------------------
void VolumeRenderingWidget::diffuseLightSpinBoxChanged(double value) {
int val = (int) (value * 100);
ui.diffuseSlider->blockSignals(true);
......@@ -493,11 +504,13 @@ void VolumeRenderingWidget::diffuseLightSpinBoxChanged(double value) {
ui.diffuseSlider->blockSignals(false);
}
// ---------------------- specularLightSliderChanged ----------------------
void VolumeRenderingWidget::specularLightSliderChanged(int value) {
double val = value / 100.0;
ui.specularSpinBox->setValue(val);
}
// ---------------------- specularLightSpinBoxChanged ----------------------
void VolumeRenderingWidget::specularLightSpinBoxChanged(double value) {
int val = (int) (value * 100);
ui.specularSlider->blockSignals(true);
......
......@@ -96,7 +96,7 @@ Action::ApplyStatus CenterMesh::apply() {
targetMesh->setModified();
}
else {
CAMITK_INFO("CenterMesh::apply transformation: Error: filter output is of type: " + QString(filter->GetOutputDataObject(0)->GetClassName()))
CAMITK_ERROR("Transform filter output is of type: " + QString(filter->GetOutputDataObject(0)->GetClassName()) + ", no vtkPointSet found.")
return ERROR;
}
......
......@@ -192,7 +192,7 @@ void MeshQuality::computeMeasure(int i) {
qualityArray = computeQuadsQuality(dynamic_cast<MeshComponent*>(getTargets().last()), i);
}
else {
// should never arrive
// should never happen
CAMITK_ERROR(tr("Elements given in input have no computable quality methods."</