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
|
/*
//
// Copyright 1997-2009 Torsten Rohlfing
//
// Copyright 2004-2013 SRI International
//
// This file is part of the Computational Morphometry Toolkit.
//
// http://www.nitrc.org/projects/cmtk/
//
// The Computational Morphometry Toolkit 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 3 of
// the License, or (at your option) any later version.
//
// The Computational Morphometry Toolkit 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 the Computational Morphometry Toolkit. If not, see
// <http://www.gnu.org/licenses/>.
//
// $Revision: 5436 $
//
// $LastChangedDate: 2018-12-10 19:01:20 -0800 (Mon, 10 Dec 2018) $
//
// $LastChangedBy: torstenrohlfing $
//
*/
#include "cmtkStudy.h"
#include <IO/cmtkFileFormat.h>
#include <IO/cmtkVolumeIO.h>
#include <string>
#include <limits.h>
namespace
cmtk
{
/** \addtogroup IO */
//@{
Study::Study()
: m_Modality( NULL ),
m_Volume( NULL ),
m_MinimumValue( 0.0 ),
m_MaximumValue( 0.0 ),
m_Padding( false ),
m_PaddingValue( 0.0 ),
m_HaveUserColorMap( false ),
m_StandardColormap( 0 ),
m_ReverseColormap( false ),
m_Black( 0.0 ),
m_White( 0.0 ),
m_Gamma( 1.0 ),
m_DisplayedImageIndex( -1 ),
m_ZoomFactor( 1 ),
m_SliceNormal( 2 )
{
}
Study::Study( const std::string& fileSystemPath, const std::string& name )
: m_Modality( NULL ),
m_Volume( NULL ),
m_MinimumValue( 0.0 ),
m_MaximumValue( 0.0 ),
m_Padding( false ),
m_PaddingValue( 0.0 ),
m_HaveUserColorMap( false ),
m_StandardColormap( 0 ),
m_ReverseColormap( false ),
m_Black( 0.0 ),
m_White( 0.0 ),
m_Gamma( 1.0 ),
m_DisplayedImageIndex( -1 ),
m_ZoomFactor( 1 ),
m_SliceNormal( 2 )
{
if ( ! fileSystemPath.empty() )
{
this->m_FileSystemPath = fileSystemPath;
this->m_Description = FileFormat::Describe( this->m_FileSystemPath );
// cut trailing '/'s off the study path.
const size_t lastChar = this->m_FileSystemPath.find_last_not_of( "/" );
if ( lastChar != std::string::npos )
{
this->m_FileSystemPath = this->m_FileSystemPath.substr( 0, lastChar+1 );
}
this->SetMakeName( name );
}
}
std::string
Study::SetMakeName( const std::string& name, const int suffix )
{
char suffixStr[10];
snprintf( suffixStr, 9, "<%d>", suffix );
if ( !name.empty() )
{
if ( suffix )
{
this->SetName( name + suffixStr );
}
else
{
this->SetName( name );
}
}
else
{
std::string studyName = name;
const size_t lastChar = studyName.find_last_not_of( "/" );
if ( lastChar != std::string::npos )
{
studyName = studyName.substr( 0, lastChar+1 );
}
const size_t lastSlash = studyName.rfind( "/" );
if ( lastSlash != std::string::npos )
{
studyName = studyName.substr( lastSlash+1 );
}
else
{
studyName = this->m_FileSystemPath;
}
const size_t dot = studyName.find( "." );
if ( dot != std::string::npos )
{
studyName = studyName.substr( 0, dot );
}
if ( suffix )
studyName = studyName + suffixStr;
this->SetName( studyName );
}
return this->m_Name;
}
bool
Study::ReadVolume( const bool reRead, const char* orientation )
{
UniformVolume::SmartPtr oldVolume( NULL );
if ( this->m_Volume && reRead )
{
oldVolume = this->m_Volume;
this->m_Volume = UniformVolume::SmartPtr( NULL );
}
if ( !this->m_Volume )
{
if ( orientation )
this->m_Volume = UniformVolume::SmartPtr( VolumeIO::ReadOriented( this->m_FileSystemPath, orientation ) );
else
this->m_Volume = UniformVolume::SmartPtr( VolumeIO::Read( this->m_FileSystemPath ) );
if ( this->m_Volume )
{
this->m_Dims = this->m_Volume->GetDims();
this->m_DisplayedImageIndex = this->m_Dims[AXIS_Z] / 2 ;
this->m_ZoomFactor = 1;
const TypedArray *dataArray = this->m_Volume->GetData();
if ( dataArray )
{
const Types::DataItemRange range = dataArray->GetRange();
this->m_MinimumValue = range.m_LowerBound;
this->m_MaximumValue = range.m_UpperBound;
this->m_Black = dataArray->GetPercentile( 0.01, 1024 );
this->m_White = dataArray->GetPercentile( 0.99, 1024 );
this->m_StandardColormap = 0;
this->m_ReverseColormap = false;
}
}
}
if ( this->m_Volume && this->m_Volume->GetData() )
{
return true;
}
this->m_Volume = oldVolume;
return false;
}
void
Study::CopyColormap( const Study* other )
{
this->m_MinimumValue = other->m_MinimumValue;
this->m_MaximumValue = other->m_MaximumValue;
this->m_StandardColormap = other->m_StandardColormap;
this->m_ReverseColormap = other->m_ReverseColormap;
this->m_Black = other->m_Black;
this->m_White = other->m_White;
this->m_Gamma = other->m_Gamma;
}
} // namespace cmtk
|