本文整理汇总了C++中VolumeCollection::GetAverageValue方法的典型用法代码示例。如果您正苦于以下问题:C++ VolumeCollection::GetAverageValue方法的具体用法?C++ VolumeCollection::GetAverageValue怎么用?C++ VolumeCollection::GetAverageValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类VolumeCollection
的用法示例。
在下文中一共展示了VolumeCollection::GetAverageValue方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: fnSave
//.........这里部分代码省略.........
<< " index " << Point3<int>(nX,nY,nZ)
<< " - wasn't supposed to get voxel but did";
throw runtime_error(ssErr.str());
}
}
}
}
}
delete vol;
}
// GetAverageValue
{
// We'll use the same volume as with GetVoxelsWithValue.
string fnVol = "test_data/testVolumeCollection-GetVoxelsWithValue.mgh";
ifstream fVol( fnMRI.c_str(), ios::in );
if ( !fVol ) {
throw runtime_error("Couldn't find necessary test data.");
}
fVol.close();
VolumeCollection* vol = new VolumeCollection();
vol->SetFileName( fnVol );
vol->LoadVolume();
// Get values of all voxels in plane x=3 and make sure it's 3.
list<VolumeLocation> lVoxels;
for ( int nZ = 0; nZ < 5; nZ++ ) {
for ( int nY = 0; nY < 5; nY++ ) {
int index[3] = { 3, nY, nZ };
VolumeLocation loc( vol->MakeVolumeLocationFromIndex( index ) );
lVoxels.push_back( loc );
}
}
float average = vol->GetAverageValue( lVoxels );
if ( average != 3.0 ) {
stringstream ssErr;
ssErr << "Failed GetAverageValue: Getting all voxels in x=3, "
<< "average should have been 3, but was " << average;
throw runtime_error( ssErr.str() );
}
// Get values of 5 voxels, one from each x plane
// (val=0,1,2,3,4), and make sure it's 2.
lVoxels.clear();
for ( int nX = 0; nX < 5; nX++ ) {
int index[3] = { nX, 3, 3 };
VolumeLocation loc( vol->MakeVolumeLocationFromIndex( index ) );
lVoxels.push_back( loc );
}
average = vol->GetAverageValue( lVoxels );
if ( average != 2.0 ) {
stringstream ssErr;
ssErr << "Failed GetAverageValue: Getting voxels in different planes, "
<< "average should have been 2, but was " << average;
throw runtime_error( ssErr.str() );
}
// Make sure we get an error for no voxels.
lVoxels.clear();
bool bDidntThrow = false;
try {
average = vol->GetAverageValue( lVoxels );
bDidntThrow = true;
} catch ( exception& e ) {}
if ( bDidntThrow ) {
stringstream ssErr;
ssErr << "Failed GetAverageValue: Didn't throw with empty list";
throw runtime_error( ssErr.str() );
}
delete vol;
}
// Check the tcl commands.
char sCommand[1024];
int rTcl;
int id = vol->GetID();
string fnTest = "test-name";
sprintf( sCommand, "SetVolumeCollectionFileName %d test-name", id );
rTcl = Tcl_Eval( iInterp, sCommand );
AssertTclOK( rTcl );
Assert( (vol->mfnMRI == fnTest),
"Setting file name via tcl didn't work" );
vol->SetDataToWorldTransform( 0 );
delete vol;
delete testVol;
} catch ( exception& e ) {
cerr << "failed with exception: " << e.what() << endl;
exit( 1 );
} catch (...) {
cerr << "failed." << endl;
exit( 1 );
}
}