本文整理汇总了C++中contourmodel::Pointer::AddVertex方法的典型用法代码示例。如果您正苦于以下问题:C++ Pointer::AddVertex方法的具体用法?C++ Pointer::AddVertex怎么用?C++ Pointer::AddVertex使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类contourmodel::Pointer
的用法示例。
在下文中一共展示了Pointer::AddVertex方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: itkNotUsed
mitk::ContourModel::Pointer mitk::ContourUtils::BackProjectContourFrom2DSlice(const Geometry3D* sliceGeometry, ContourModel* contourIn2D, bool itkNotUsed( correctionForIpSegmentation ) )
{
if ( !sliceGeometry || !contourIn2D ) return NULL;
ContourModel::Pointer worldContour = ContourModel::New();
worldContour->Initialize(*contourIn2D);
int numberOfTimesteps = contourIn2D->GetTimeGeometry()->CountTimeSteps();
for(int currentTimestep = 0; currentTimestep < numberOfTimesteps; currentTimestep++)
{
ContourModel::VertexIterator iter = contourIn2D->Begin(currentTimestep);
ContourModel::VertexIterator end = contourIn2D->End(currentTimestep);
while( iter != end)
{
Point3D currentPointIn2D = (*iter)->Coordinates;
Point3D worldPointIn3D;
worldPointIn3D.Fill(0.0);
sliceGeometry->IndexToWorld( currentPointIn2D, worldPointIn3D );
//MITK_INFO << "index " << currentPointIn2D << " world " << worldPointIn3D << std::endl;
worldContour->AddVertex( worldPointIn3D, currentTimestep );
iter++;
}
}
return worldContour;
}
示例2: ipMITKSegmentationCreateGrowerHistory
/**
3.1 Create a skeletonization of the segmentation and try to find a nice cut
3.1.1 Call a ipSegmentation algorithm to create a nice cut
3.1.2 Set the result of this algorithm as the feedback contour
*/
bool mitk::RegionGrowingTool::OnMousePressedInside( StateMachineAction*, InteractionEvent* interactionEvent, mitkIpPicDescriptor* workingPicSlice, int initialWorkingOffset)
{
if ( SegTool2D::CanHandleEvent(interactionEvent) < 1.0 )
return false;
mitk::InteractionPositionEvent* positionEvent = dynamic_cast<mitk::InteractionPositionEvent*>( interactionEvent );
//const PositionEvent* positionEvent = dynamic_cast<const PositionEvent*>(stateEvent->GetEvent()); // checked in OnMousePressed
// 3.1.1. Create a skeletonization of the segmentation and try to find a nice cut
// apply the skeletonization-and-cut algorithm
// generate contour to remove
// set m_ReferenceSlice = NULL so nothing will happen during mouse move
// remember to fill the contour with 0 in mouserelease
mitkIpPicDescriptor* segmentationHistory = ipMITKSegmentationCreateGrowerHistory( workingPicSlice, m_LastWorkingSeed, NULL ); // free again
if (segmentationHistory)
{
tCutResult cutContour = ipMITKSegmentationGetCutPoints( workingPicSlice, segmentationHistory, initialWorkingOffset ); // tCutResult is a ipSegmentation type
mitkIpPicFree( segmentationHistory );
if (cutContour.cutIt)
{
int timestep = positionEvent->GetSender()->GetTimeStep();
// 3.1.2 copy point from float* to mitk::Contour
ContourModel::Pointer contourInImageIndexCoordinates = ContourModel::New();
contourInImageIndexCoordinates->Expand(timestep + 1);
contourInImageIndexCoordinates->SetClosed(true, timestep);
Point3D newPoint;
for (int index = 0; index < cutContour.deleteSize; ++index)
{
newPoint[0] = cutContour.deleteCurve[ 2 * index + 0 ] - 0.5;//correction is needed because the output of the algorithm is center based
newPoint[1] = cutContour.deleteCurve[ 2 * index + 1 ] - 0.5;//and we want our contour displayed corner based.
newPoint[2] = 0.0;
contourInImageIndexCoordinates->AddVertex( newPoint, timestep );
}
free(cutContour.traceline);
free(cutContour.deleteCurve); // perhaps visualize this for fun?
free(cutContour.onGradient);
ContourModel::Pointer contourInWorldCoordinates = FeedbackContourTool::BackProjectContourFrom2DSlice( m_WorkingSlice->GetGeometry(), contourInImageIndexCoordinates, true ); // true: sub 0.5 for ipSegmentation correction
FeedbackContourTool::SetFeedbackContour( *contourInWorldCoordinates );
FeedbackContourTool::SetFeedbackContourVisible(true);
mitk::RenderingManager::GetInstance()->RequestUpdate( positionEvent->GetSender()->GetRenderWindow() );
m_FillFeedbackContour = true;
}
else
{
m_FillFeedbackContour = false;
}
}
else
{
m_FillFeedbackContour = false;
}
m_ReferenceSlice = NULL;
return true;
}
示例3: oneContourOffset
//.........这里部分代码省略.........
mitkIpPicDescriptor* regionGrowerResult = ipMITKSegmentationGrowRegion4N( m_OriginalPicSlice,
m_SeedPointMemoryOffset, // seed point
true, // grayvalue interval relative to seed point gray value?
m_LowerThreshold,
m_UpperThreshold,
0, // continue until done (maxIterations == 0)
NULL, // allocate new memory (only this time, on mouse move we'll reuse the old buffer)
oneContourOffset, // a pixel that is near the resulting contour
ignored // ignored by us
);
if (!regionGrowerResult || oneContourOffset == -1)
{
ContourModel::Pointer dummyContour = ContourModel::New();
dummyContour->Initialize();
FeedbackContourTool::SetFeedbackContour( *dummyContour );
if (regionGrowerResult) ipMITKSegmentationFree(regionGrowerResult);
return NULL;
}
// 3. We smooth the result a little to reduce contour complexity
bool smoothResult( true ); // currently fixed, perhaps remove else block
mitkIpPicDescriptor* smoothedRegionGrowerResult;
if (smoothResult)
{
// Smooth the result (otherwise very detailed contour)
smoothedRegionGrowerResult = SmoothIPPicBinaryImage( regionGrowerResult, oneContourOffset );
ipMITKSegmentationFree( regionGrowerResult );
}
else
{
smoothedRegionGrowerResult = regionGrowerResult;
}
// 4. convert the result of region growing into a mitk::Contour
// At this point oneContourOffset could be useless, if smoothing destroyed a thin bridge. In these
// cases, we have two or more unconnected segmentation regions, and we don't know, which one is touched by oneContourOffset.
// In the bad case, the contour is not the one around our seedpoint, so the result looks very strange to the user.
// -> we remove the point where the contour started so far. Then we look from the bottom of the image for the first segmentation pixel
// and start another contour extraction from there. This is done, until the seedpoint is inside the contour
int numberOfContourPoints( 0 );
int newBufferSize( 0 );
float* contourPoints = ipMITKSegmentationGetContour8N( smoothedRegionGrowerResult, oneContourOffset, numberOfContourPoints, newBufferSize ); // memory allocated with malloc
if (contourPoints)
{
while ( !ipMITKSegmentationIsInsideContour( contourPoints, // contour
numberOfContourPoints, // points in contour
m_SeedPointMemoryOffset % smoothedRegionGrowerResult->n[0], // test point x
m_SeedPointMemoryOffset / smoothedRegionGrowerResult->n[0] // test point y
) )
{
// we decide that this cannot be part of the segmentation because the seedpoint is not contained in the contour (fill the 4-neighborhood with 0)
ipMITKSegmentationReplaceRegion4N( smoothedRegionGrowerResult, oneContourOffset, 0 );
// move the contour offset to the last row (x position of the seed point)
int rowLength = smoothedRegionGrowerResult->n[0]; // number of pixels in a row
oneContourOffset = m_SeedPointMemoryOffset % smoothedRegionGrowerResult->n[0] // x of seed point
+ rowLength*(smoothedRegionGrowerResult->n[1]-1); // y of last row
while ( oneContourOffset >=0
&& (*(static_cast<ipMITKSegmentationTYPE*>(smoothedRegionGrowerResult->data) + oneContourOffset) == 0) )
{
oneContourOffset -= rowLength; // if pixel at data+oneContourOffset is 0, then move up one row
}
if ( oneContourOffset < 0 )
{
break; // just use the last contour we found
}
free(contourPoints); // release contour memory
contourPoints = ipMITKSegmentationGetContour8N( smoothedRegionGrowerResult, oneContourOffset, numberOfContourPoints, newBufferSize ); // memory allocated with malloc
}
// copy point from float* to mitk::Contour
ContourModel::Pointer contourInImageIndexCoordinates = ContourModel::New();
contourInImageIndexCoordinates->Expand(timestep + 1);
contourInImageIndexCoordinates->SetClosed(true, timestep);
Point3D newPoint;
for (int index = 0; index < numberOfContourPoints; ++index)
{
newPoint[0] = contourPoints[ 2 * index + 0 ] - 0.5;//correction is needed because the output of the algorithm is center based
newPoint[1] = contourPoints[ 2 * index + 1 ] - 0.5;//and we want our contour displayed corner based.
newPoint[2] = 0;
contourInImageIndexCoordinates->AddVertex( newPoint, timestep );
}
free(contourPoints);
ContourModel::Pointer contourInWorldCoordinates = FeedbackContourTool::BackProjectContourFrom2DSlice( m_ReferenceSlice->GetGeometry(), contourInImageIndexCoordinates, true ); // true: sub 0.5 for ipSegmentation correctio
FeedbackContourTool::SetFeedbackContour( *contourInWorldCoordinates );
}
// 5. Result HAS TO BE freed by caller, contains the binary region growing result
return smoothedRegionGrowerResult;
}
示例4: upperLeft
//.........这里部分代码省略.........
}
// QuarterCycle is full! Now copy quarter cycle to other quarters.
if( !evenSize )
{
std::vector< mitk::Point2D >::const_iterator it = quarterCycleUpperRight.begin();
while( it != quarterCycleUpperRight.end() )
{
mitk::Point2D p;
p = *it;
// the contour points in the lower right corner have same position but with negative y values
p[1] *= -1;
quarterCycleLowerRight.push_back(p);
// the contour points in the lower left corner have same position
// but with both x,y negative
p[0] *= -1;
quarterCycleLowerLeft.push_back(p);
// the contour points in the upper left corner have same position
// but with x negative
p[1] *= -1;
quarterCycleUpperLeft.push_back(p);
it++;
}
}
else
{
std::vector< mitk::Point2D >::const_iterator it = quarterCycleUpperRight.begin();
while( it != quarterCycleUpperRight.end() )
{
mitk::Point2D p,q;
p = *it;
q = p;
// the contour points in the lower right corner have same position but with negative y values
q[1] *= -1;
// correct for moved offset if size even = the midpoint is not the midpoint of the current pixel
// but its upper rigt corner
q[1] += 1;
quarterCycleLowerRight.push_back(q);
q = p;
// the contour points in the lower left corner have same position
// but with both x,y negative
q[1] = -1.0f * q[1] + 1;
q[0] = -1.0f * q[0] + 1;
quarterCycleLowerLeft.push_back(q);
// the contour points in the upper left corner have same position
// but with x negative
q = p;
q[0] *= -1;
q[0] += 1;
quarterCycleUpperLeft.push_back(q);
it++;
}
}
// fill contour with poins in right ordering, starting with the upperRight block
mitk::Point3D tempPoint;
for (unsigned int i=0; i<quarterCycleUpperRight.size(); i++)
{
tempPoint[0] = quarterCycleUpperRight[i][0];
tempPoint[1] = quarterCycleUpperRight[i][1];
tempPoint[2] = 0;
contourInImageIndexCoordinates->AddVertex( tempPoint );
}
// the lower right has to be parsed in reverse order
for (int i=quarterCycleLowerRight.size()-1; i>=0; i--)
{
tempPoint[0] = quarterCycleLowerRight[i][0];
tempPoint[1] = quarterCycleLowerRight[i][1];
tempPoint[2] = 0;
contourInImageIndexCoordinates->AddVertex( tempPoint );
}
for (unsigned int i=0; i<quarterCycleLowerLeft.size(); i++)
{
tempPoint[0] = quarterCycleLowerLeft[i][0];
tempPoint[1] = quarterCycleLowerLeft[i][1];
tempPoint[2] = 0;
contourInImageIndexCoordinates->AddVertex( tempPoint );
}
// the upper left also has to be parsed in reverse order
for (int i=quarterCycleUpperLeft.size()-1; i>=0; i--)
{
tempPoint[0] = quarterCycleUpperLeft[i][0];
tempPoint[1] = quarterCycleUpperLeft[i][1];
tempPoint[2] = 0;
contourInImageIndexCoordinates->AddVertex( tempPoint );
}
m_MasterContour = contourInImageIndexCoordinates;
}
示例5: CheckIfCurrentSliceHasChanged
/**
Insert the point to the feedback contour,finish to build the contour and at the same time the painting function
*/
void mitk::PaintbrushTool::MouseMoved(mitk::InteractionEvent* interactionEvent, bool leftMouseButtonPressed)
{
mitk::InteractionPositionEvent* positionEvent = dynamic_cast<mitk::InteractionPositionEvent*>( interactionEvent );
CheckIfCurrentSliceHasChanged( positionEvent );
if ( m_LastContourSize != m_Size )
{
UpdateContour( positionEvent );
m_LastContourSize = m_Size;
}
Point3D worldCoordinates = positionEvent->GetPositionInWorld();
Point3D indexCoordinates;
m_WorkingSlice->GetGeometry()->WorldToIndex( worldCoordinates, indexCoordinates );
MITK_DEBUG << "Mouse at W " << worldCoordinates << std::endl;
MITK_DEBUG << "Mouse at I " << indexCoordinates << std::endl;
// round to nearest voxel center (abort if this hasn't changed)
if ( m_Size % 2 == 0 ) // even
{
indexCoordinates[0] = ROUND( indexCoordinates[0]);// /*+ 0.5*/) + 0.5;
indexCoordinates[1] = ROUND( indexCoordinates[1]);// /*+ 0.5*/ ) + 0.5;
}
else // odd
{
indexCoordinates[0] = ROUND( indexCoordinates[0] ) ;
indexCoordinates[1] = ROUND( indexCoordinates[1] ) ;
}
static Point3D lastPos; // uninitialized: if somebody finds out how this can be initialized in a one-liner, tell me
if ( fabs(indexCoordinates[0] - lastPos[0]) > mitk::eps ||
fabs(indexCoordinates[1] - lastPos[1]) > mitk::eps ||
fabs(indexCoordinates[2] - lastPos[2]) > mitk::eps ||
leftMouseButtonPressed
)
{
lastPos = indexCoordinates;
}
else
{
MITK_DEBUG << "." << std::flush;
return;
}
MITK_DEBUG << "Mouse at C " << indexCoordinates;
int timestep = positionEvent->GetSender()->GetTimeStep();
ContourModel::Pointer contour = ContourModel::New();
contour->Expand(timestep + 1);
contour->SetClosed(true, timestep);
ContourModel::VertexIterator it = m_MasterContour->Begin();
ContourModel::VertexIterator end = m_MasterContour->End();
while(it != end)
{
Point3D point = (*it)->Coordinates;
point[0] += indexCoordinates[ 0 ];
point[1] += indexCoordinates[ 1 ];
contour->AddVertex( point, timestep );
it++;
}
if (leftMouseButtonPressed)
{
FeedbackContourTool::FillContourInSlice( contour, timestep, m_WorkingSlice, m_PaintingPixelValue );
m_WorkingNode->SetData(m_WorkingSlice);
m_WorkingNode->Modified();
}
// visualize contour
ContourModel::Pointer displayContour = this->GetFeedbackContour();
displayContour->Clear();
ContourModel::Pointer tmp = FeedbackContourTool::BackProjectContourFrom2DSlice( m_WorkingSlice->GetGeometry(), /*displayContour*/contour );
// copy transformed contour into display contour
it = tmp->Begin();
end = tmp->End();
while(it != end)
{
Point3D point = (*it)->Coordinates;
displayContour->AddVertex( point, timestep );
it++;
}
m_FeedbackContourNode->GetData()->Modified();
assert( positionEvent->GetSender()->GetRenderWindow() );
//.........这里部分代码省略.........
示例6: if
//.........这里部分代码省略.........
{
unsigned int lastValidPixel = size-1; // initialization, will be changed lateron
bool inSeg = true; // inside segmentation?
for ( ; oneContourOffset < size; ++oneContourOffset )
{
if ( ( data[oneContourOffset] == 0 ) && inSeg ) // pixel 0 and inside-flag set: this happens at the first pixel outside a filled region
{
inSeg = false;
lastValidPixel = oneContourOffset - 1; // store the last pixel position inside a filled region
break;
}
else // pixel 1, inside-flag doesn't matter: this happens while we are inside a filled region
{
inSeg = true; // first iteration lands here
}
}
oneContourOffset = lastValidPixel;
}
else
{
MITK_ERROR << "Fill/Erase was never intended to work with other than binary images." << std::endl;
m_FillContour = false;
return false;
}
if (oneContourOffset == size) // nothing found until end of slice
{
m_FillContour = false;
return false;
}
int numberOfContourPoints( 0 );
int newBufferSize( 0 );
//MITK_INFO << "getting contour from offset " << oneContourOffset << " ("<<oneContourOffset%originalPicSlice->n[0]<<","<<oneContourOffset/originalPicSlice->n[0]<<")"<<std::endl;
float* contourPoints = ipMITKSegmentationGetContour8N( originalPicSlice, oneContourOffset, numberOfContourPoints, newBufferSize ); // memory allocated with malloc
//MITK_INFO << "contourPoints " << contourPoints << " (N="<<numberOfContourPoints<<")"<<std::endl;
assert(contourPoints == NULL || numberOfContourPoints > 0);
bool cursorInsideContour = ipMITKSegmentationIsInsideContour( contourPoints, numberOfContourPoints, projectedPointIn2D[0], projectedPointIn2D[1]);
// decide if contour should be filled or not
m_FillContour = cursorInsideContour;
if (m_FillContour)
{
// copy point from float* to mitk::Contour
ContourModel::Pointer contourInImageIndexCoordinates = ContourModel::New();
contourInImageIndexCoordinates->Expand(timeStep + 1);
contourInImageIndexCoordinates->SetClosed(true, timeStep);
Point3D newPoint;
for (int index = 0; index < numberOfContourPoints; ++index)
{
newPoint[0] = contourPoints[ 2 * index + 0 ] - 0.5;
newPoint[1] = contourPoints[ 2 * index + 1] - 0.5;
newPoint[2] = 0;
contourInImageIndexCoordinates->AddVertex(newPoint, timeStep);
}
m_SegmentationContourInWorldCoordinates = FeedbackContourTool::BackProjectContourFrom2DSlice( workingSlice->GetGeometry(), contourInImageIndexCoordinates, true ); // true, correct the result from ipMITKSegmentationGetContour8N
// 3. Show the contour
FeedbackContourTool::SetFeedbackContour( *m_SegmentationContourInWorldCoordinates );
FeedbackContourTool::SetFeedbackContourVisible(true);
mitk::RenderingManager::GetInstance()->RequestUpdate(positionEvent->GetSender()->GetRenderWindow());
}
// always generate a second contour, containing the whole image (used when CTRL is pressed)
{
// copy point from float* to mitk::Contour
ContourModel::Pointer contourInImageIndexCoordinates = ContourModel::New();
contourInImageIndexCoordinates->Expand(timeStep + 1);
contourInImageIndexCoordinates->SetClosed(true, timeStep);
Point3D newPoint;
newPoint[0] = 0; newPoint[1] = 0; newPoint[2] = 0.0;
contourInImageIndexCoordinates->AddVertex( newPoint, timeStep );
newPoint[0] = originalPicSlice->n[0]; newPoint[1] = 0; newPoint[2] = 0.0;
contourInImageIndexCoordinates->AddVertex( newPoint, timeStep );
newPoint[0] = originalPicSlice->n[0]; newPoint[1] = originalPicSlice->n[1]; newPoint[2] = 0.0;
contourInImageIndexCoordinates->AddVertex( newPoint, timeStep );
newPoint[0] = 0; newPoint[1] = originalPicSlice->n[1]; newPoint[2] = 0.0;
contourInImageIndexCoordinates->AddVertex( newPoint, timeStep );
m_WholeImageContourInWorldCoordinates = FeedbackContourTool::BackProjectContourFrom2DSlice( workingSlice->GetGeometry(), contourInImageIndexCoordinates, true ); // true, correct the result from ipMITKSegmentationGetContour8N
// 3. Show the contour
FeedbackContourTool::SetFeedbackContour( *m_SegmentationContourInWorldCoordinates );
FeedbackContourTool::SetFeedbackContourVisible(true);
mitk::RenderingManager::GetInstance()->RequestUpdate(positionEvent->GetSender()->GetRenderWindow());
}
free(contourPoints);
return true;
}