1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457
|
/*LICENSE_START*/
/*
* Copyright 1995-2002 Washington University School of Medicine
*
* http://brainmap.wustl.edu
*
* This file is part of CARET.
*
* CARET is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* CARET is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with CARET; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
/*LICENSE_END*/
#include "AreaColorFile.h"
#include "BorderColorFile.h"
#include "BorderProjectionFile.h"
#include "BrainModelSurface.h"
#include "BrainModelSurfaceBorderLandmarkIdentification.h"
#include "BrainSet.h"
#include "CommandSurfaceBorderLandmarkIdentification.h"
#include "FileFilters.h"
#include "FociColorFile.h"
#include "FociProjectionFile.h"
#include "MetricFile.h"
#include "PaintFile.h"
#include "ProgramParameters.h"
#include "ScriptBuilderParameters.h"
#include "SurfaceShapeFile.h"
#include "VocabularyFile.h"
#include "VolumeFile.h"
/**
* constructor.
*/
CommandSurfaceBorderLandmarkIdentification::CommandSurfaceBorderLandmarkIdentification()
: CommandBase("-surface-border-landmark-identification",
"SURFACE BORDER LANDMARK IDENTIFICATION")
{
}
/**
* destructor.
*/
CommandSurfaceBorderLandmarkIdentification::~CommandSurfaceBorderLandmarkIdentification()
{
}
/**
* get the script builder parameters.
*/
void
CommandSurfaceBorderLandmarkIdentification::getScriptBuilderParameters(ScriptBuilderParameters& paramsOut) const
{
std::vector<StereotaxicSpace> spaces;
BrainModelSurfaceBorderLandmarkIdentification::getSupportedStereotaxicSpaces(spaces);
std::vector<QString> spaceNames;
for (unsigned int i = 0; i < spaces.size(); i++) {
spaceNames.push_back(spaces[i].getName());
}
paramsOut.clear();
paramsOut.addListOfItems("Stereotaxic Space", spaceNames, spaceNames);
paramsOut.addFile("Anatomy Volume File Name", FileFilters::getVolumeGenericFileFilter());
paramsOut.addFile("Fiducial Coordinate File Name", FileFilters::getCoordinateGenericFileFilter());
paramsOut.addFile("Inflated Coordinate File Name", FileFilters::getCoordinateGenericFileFilter());
paramsOut.addFile("Very Inflated Coordinate File Name", FileFilters::getCoordinateGenericFileFilter());
paramsOut.addFile("Ellipsoid Coordinate File Name", FileFilters::getCoordinateGenericFileFilter());
paramsOut.addFile("Closed Topology File Name", FileFilters::getTopologyGenericFileFilter());
paramsOut.addFile("Input Paint File Name", FileFilters::getPaintFileFilter());
paramsOut.addFile("Output Paint File Name", FileFilters::getPaintFileFilter());
paramsOut.addString("Input Paint File Geography Column Name or Number", "Geography");
paramsOut.addFile("Surface Shape File Name", FileFilters::getSurfaceShapeFileFilter());
paramsOut.addString("Surface Shape File Depth Column Name or Number", "Depth");
paramsOut.addFile("Input Area Color File Name", FileFilters::getAreaColorFileFilter());
paramsOut.addFile("Output Area Color File Name", FileFilters::getAreaColorFileFilter());
paramsOut.addFile("Input Vocabulary File Name", FileFilters::getVocabularyFileFilter());
paramsOut.addFile("Output Vocabulary File Name", FileFilters::getVocabularyFileFilter());
paramsOut.addFile("Input Border Projection File Name", FileFilters::getBorderProjectionFileFilter());
paramsOut.addFile("Output Border Projection File Name", FileFilters::getBorderProjectionFileFilter());
paramsOut.addFile("Input Border Color File Name", FileFilters::getBorderColorFileFilter());
paramsOut.addFile("Output Border Color File Name", FileFilters::getBorderColorFileFilter());
// paramsOut.addFile("Output Foci Projection File Name", FileFilters::getFociProjectionFileFilter());
// paramsOut.addFile("Output Foci Color File Name", FileFilters::getFociColorFileFilter());
}
/**
* get full help information.
*/
QString
CommandSurfaceBorderLandmarkIdentification::getHelpInformation() const
{
std::vector<StereotaxicSpace> spaces;
BrainModelSurfaceBorderLandmarkIdentification::getSupportedStereotaxicSpaces(spaces);
QString helpInfo =
(indent3 + getShortDescription() + "\n"
+ indent6 + parameters->getProgramNameWithoutPath() + " " + getOperationSwitch() + " \n"
+ indent9 + "<stereotaxic-space-name> \n"
+ indent9 + "<input-anatomical-volume-file-name>\n"
+ indent9 + "<input-fiducial-coordinate-file-name>\n"
+ indent9 + "<input-inflated-coord-file-name> \n"
+ indent9 + "<input-very-inflated-coord-file-name> \n"
+ indent9 + "<input-ellipsoid-coord-file-name> \n"
+ indent9 + "<input-closed-topo-file-name> \n"
+ indent9 + "<input-paint-file-name> \n"
+ indent9 + "<output-paint-file-name> \n"
+ indent9 + "<input-paint-file-geography-column-name-or-number> \n"
+ indent9 + "<input-surface-shape-file-name> \n"
+ indent9 + "<input-surface-shape-file-depth-column-name-or-number> \n"
+ indent9 + "<input-area-color-file-name> \n"
+ indent9 + "<output-area-color-file-name> \n"
+ indent9 + "<input-vocabulary-file-name> \n"
+ indent9 + "<output-vocabulary-file-name> \n"
+ indent9 + "<input-border-projection-file> \n"
+ indent9 + "<output-border-projection-file> \n"
+ indent9 + "<input-border-color-file> \n"
+ indent9 + "<output-border-color-file> \n"
// + indent9 + "<output-foci-projection-file> \n"
// + indent9 + "<output-foci-color-file> \n"
+ indent9 + "\n"
+ indent9 + "Draw borders on landmarks for flattening and registration.\n"
+ indent9 + "The landmarks identified are:\n"
+ indent9 + " Calcarine Sulcus\n"
+ indent9 + " Central Sulcus\n"
+ indent9 + " Medial Wall\n"
+ indent9 + " Superior Temporal Gyrus\n"
+ indent9 + " Sylvian Fissure\n"
+ indent9 + "\n"
+ indent9 + "The anatomical volume is used to generate the corpus\n"
+ indent9 + "callosum. If desired, you may provide an anatomical \n"
+ indent9 + "volume that contains ONLY the corpus callosum. If so,\n"
+ indent9 + "the anatomical volume's filename MUST contain the\n"
+ indent9 + "case insensitive words \"corpus\" and \"callosum\".\n"
+ indent9 + "\n"
+ indent9 + "Supported stereotaxic spaces are: \n");
for (unsigned int i = 0; i < spaces.size(); i++) {
helpInfo += (indent9 + " " + spaces[i].getName() + "\n");
}
helpInfo += (
indent9 + "\n");
return helpInfo;
}
/**
* execute the command.
*/
void
CommandSurfaceBorderLandmarkIdentification::executeCommand() throw (BrainModelAlgorithmException,
CommandException,
FileException,
ProgramParametersException,
StatisticException)
{
bool doLandmarksFlag = true;
bool doFlattenFlag = true;
const QString stereotaxicSpaceName =
parameters->getNextParameterAsString("Stereotaxic Space Name");
const QString anatomicalVolumeFileName =
parameters->getNextParameterAsString("Input Anatomical Volume File Name");
const QString fiducialCoordFileName =
parameters->getNextParameterAsString("Input Fiducial Coord File Name");
const QString inflatedCoordFileName =
parameters->getNextParameterAsString("Input Inflated Coord File Name");
const QString veryInflatedCoordFileName =
parameters->getNextParameterAsString("Input Very Inflated Coord File Name");
const QString ellipsoidCoordFileName =
parameters->getNextParameterAsString("Input Ellipsoid Coord File Name");
const QString inputTopoFileName =
parameters->getNextParameterAsString("Input Closed Topology File Name");
const QString inputPaintFileName =
parameters->getNextParameterAsString("Input Paint File Name");
const QString outputPaintFileName =
parameters->getNextParameterAsString("Output Paint File Name");
const QString inputPaintFileGeographyColumnNameOrNumber =
parameters->getNextParameterAsString("Input Paint File Geography Column Name or Number");
const QString inputSurfaceShapeFileName =
parameters->getNextParameterAsString("Input Surface Shape File Name");
const QString inputSurfaceShapeFileDepthColumnNameOrNumber =
parameters->getNextParameterAsString("Input Surface Shape File Depth Column Name or Number");
const QString inputAreaColorFileName =
parameters->getNextParameterAsString("Input Area Color File Name");
const QString outputAreaColorFileName =
parameters->getNextParameterAsString("Output Area Color File Name");
const QString inputVocabularyFileName =
parameters->getNextParameterAsString("Input Vocabulary File Name");
const QString outputVocabularyFileName =
parameters->getNextParameterAsString("Output Vocabulary File Name");
const QString inputBorderProjectionFileName =
parameters->getNextParameterAsString("Input Border Projection File Name");
const QString outputBorderProjectionFileName =
parameters->getNextParameterAsString("Output Border Projection File Name");
const QString inputBorderColorFileName =
parameters->getNextParameterAsString("Input Border Color File Name");
const QString outputBorderColorFileName =
parameters->getNextParameterAsString("Output Border Color File Name");
//const QString outputFociProjectionFileName =
// parameters->getNextParameterAsString("Output Foci Projection File Name");
//const QString outputFociColorFileName =
// parameters->getNextParameterAsString("Output Foci Color File Name");
//
// Optional parameters
//
while (parameters->getParametersAvailable()) {
const QString paramName = parameters->getNextParameterAsString("Optional Param");
if (paramName == "-no-landmarks") {
doLandmarksFlag = false;
}
else if (paramName == "-no-flatten") {
doFlattenFlag = false;
}
else {
throw CommandException("Unrecognized parameter: " + paramName);
}
}
//
// Check name of stereotaxic space
//
if (StereotaxicSpace::validStereotaxicSpaceName(stereotaxicSpaceName) == false) {
throw CommandException(stereotaxicSpaceName
+ " is not the name of a valid stereotaxic space.");
}
StereotaxicSpace stereotaxicSpace(stereotaxicSpaceName);
//
// Create a spec file
//
SpecFile specFile;
specFile.setAllFileSelections(SpecFile::SPEC_FALSE);
specFile.addToSpecFile(SpecFile::getVolumeAnatomyFileTag(),
anatomicalVolumeFileName,
"",
SpecFile::SPEC_FALSE);
specFile.addToSpecFile(SpecFile::getFiducialCoordFileTag(),
fiducialCoordFileName,
"",
SpecFile::SPEC_FALSE);
specFile.addToSpecFile(SpecFile::getInflatedCoordFileTag(),
inflatedCoordFileName,
"",
SpecFile::SPEC_FALSE);
specFile.addToSpecFile(SpecFile::getVeryInflatedCoordFileTag(),
veryInflatedCoordFileName,
"",
SpecFile::SPEC_FALSE);
specFile.addToSpecFile(SpecFile::getEllipsoidCoordFileTag(),
ellipsoidCoordFileName,
"",
SpecFile::SPEC_FALSE);
specFile.addToSpecFile(SpecFile::getClosedTopoFileTag(),
inputTopoFileName,
"",
SpecFile::SPEC_FALSE);
specFile.addToSpecFile(SpecFile::getPaintFileTag(),
inputPaintFileName,
"",
SpecFile::SPEC_FALSE);
specFile.addToSpecFile(SpecFile::getSurfaceShapeFileTag(),
inputSurfaceShapeFileName,
"",
SpecFile::SPEC_FALSE);
if (inputAreaColorFileName.isEmpty() == false) {
if (QFile::exists(inputAreaColorFileName)) {
specFile.addToSpecFile(SpecFile::getAreaColorFileTag(),
inputAreaColorFileName,
"",
SpecFile::SPEC_FALSE);
}
}
if (inputVocabularyFileName.isEmpty() == false) {
if (QFile::exists(inputVocabularyFileName)) {
specFile.addToSpecFile(SpecFile::getVocabularyFileTag(),
inputVocabularyFileName,
"",
SpecFile::SPEC_FALSE);
}
}
if (inputBorderProjectionFileName.isEmpty() == false) {
if (QFile::exists(inputBorderProjectionFileName)) {
specFile.addToSpecFile(SpecFile::getBorderProjectionFileTag(),
inputBorderProjectionFileName,
"",
SpecFile::SPEC_FALSE);
}
}
if (inputBorderColorFileName.isEmpty() == false) {
if (QFile::exists(inputBorderColorFileName)) {
specFile.addToSpecFile(SpecFile::getBorderColorFileTag(),
inputBorderColorFileName,
"",
SpecFile::SPEC_FALSE);
}
}
//
// Read the spec file into a brain set
//
QString errorMessage;
BrainSet brainSet(true);
if (brainSet.readSpecFile(specFile, "temp", errorMessage)) {
const QString msg("ERROR: Reading spec file data files: \n"
+ errorMessage);
throw CommandException(msg);
}
//
// Find the fiducial and very inflated surfaces
//
BrainModelSurface* fiducialSurface = NULL;
BrainModelSurface* inflatedSurface = NULL;
BrainModelSurface* veryInflatedSurface = NULL;
BrainModelSurface* ellipsoidSurface = NULL;
for (int i = 0; i < brainSet.getNumberOfBrainModels(); i++) {
BrainModelSurface* bms = brainSet.getBrainModelSurface(i);
if (bms != NULL) {
if (bms->getSurfaceType() == BrainModelSurface::SURFACE_TYPE_FIDUCIAL) {
fiducialSurface = bms;
}
else if (bms->getSurfaceType() == BrainModelSurface::SURFACE_TYPE_INFLATED) {
inflatedSurface = bms;
}
else if (bms->getSurfaceType() == BrainModelSurface::SURFACE_TYPE_VERY_INFLATED) {
veryInflatedSurface = bms;
}
else if (bms->getSurfaceType() == BrainModelSurface::SURFACE_TYPE_ELLIPSOIDAL) {
ellipsoidSurface = bms;
}
}
}
if (fiducialSurface == NULL) {
throw CommandException("Unable to find fiducial surface.");
}
if (inflatedSurface == NULL) {
throw CommandException("Unable to find inflated surface.");
}
if (veryInflatedSurface == NULL) {
throw CommandException("Unable to find very inflated surface.");
}
if (ellipsoidSurface == NULL) {
throw CommandException("Unable to find ellipsoid surface.");
}
//
// Get the paint and shape column numbers
//
const int paintFileGeographyColumnNumber =
brainSet.getPaintFile()->getColumnFromNameOrNumber(inputPaintFileGeographyColumnNameOrNumber, false);
const int surfaceShapeFileDepthColumnNumber =
brainSet.getSurfaceShapeFile()->getColumnFromNameOrNumber(inputSurfaceShapeFileDepthColumnNameOrNumber, false);
//
// Get any existing borders
//
BorderProjectionFile borderProjectionFile;
brainSet.getBorderSet()->copyBordersToBorderProjectionFile(borderProjectionFile);
int operation = 0;
if (doLandmarksFlag) {
operation |=
BrainModelSurfaceBorderLandmarkIdentification::OPERATION_ID_REGISTRATION_LANDMARKS;
}
if (doFlattenFlag) {
operation |=
BrainModelSurfaceBorderLandmarkIdentification::OPERATION_ID_FLATTENING_LANDMARKS;
}
//
// Identify the sulci
//
BrainModelSurfaceBorderLandmarkIdentification bmslg(&brainSet,
stereotaxicSpace,
brainSet.getVolumeAnatomyFile(0),
fiducialSurface,
inflatedSurface,
veryInflatedSurface,
ellipsoidSurface,
brainSet.getSurfaceShapeFile(),
surfaceShapeFileDepthColumnNumber,
brainSet.getPaintFile(),
paintFileGeographyColumnNumber,
brainSet.getAreaColorFile(),
&borderProjectionFile,
brainSet.getBorderColorFile(),
brainSet.getVocabularyFile(),
operation);
errorMessage = "";
try {
bmslg.execute();
}
catch (BrainModelAlgorithmException& e) {
errorMessage = ("identifying landmarks: "
+ e.whatQString());
}
//
// Save the borders
//
borderProjectionFile.writeFile(outputBorderProjectionFileName);
brainSet.getBorderColorFile()->writeFile(outputBorderColorFileName);
//
// Write the paint file
//
if (outputPaintFileName.isEmpty() == false) {
brainSet.getPaintFile()->writeFile(outputPaintFileName);
}
//
// Write the area color file
//
if (outputAreaColorFileName.isEmpty() == false) {
brainSet.getAreaColorFile()->writeFile(outputAreaColorFileName);
}
//
// Write the vocabulary file
//
if (outputVocabularyFileName.isEmpty() == false) {
brainSet.getVocabularyFile()->writeFile(outputVocabularyFileName);
}
/*
//
// Write the foci and foci projection files
//
FociProjectionFile* fpf = (FociProjectionFile*)bmslg.getFociProjectionFile();
fpf->writeFile(outputFociProjectionFileName);
brainSet.addToSpecFile(SpecFile::fociProjectionFileTag,
outputFociProjectionFileName);
FociColorFile* fcf = (FociColorFile*)bmslg.getFociColorFile();
fcf->writeFile(outputFociColorFileName);
brainSet.addToSpecFile(SpecFile::fociColorFileTag,
outputFociColorFileName);
*/
if (errorMessage.isEmpty() == false) {
throw CommandException(errorMessage);
}
}
|