[Insight-users] VectorContainer, removing element
Luis Ibanez
luis.ibanez at kitware.com
Thu, 05 Feb 2004 18:21:36 -0500
Hi Laurent,
You may find useful to look at the STL documentation
http://www.sgi.com/tech/stl/table_of_contents.html
In particular to the std::vector class
http://www.sgi.com/tech/stl/Vector.html
Note the methods
iterator erase(iterator pos)
iterator erase(iterator first, iterator last
Since the itk::VectorContainer derives from
the std::vector, you can simply invoke any
of these two erase methods.
Note that erasing invalidates the iterators
that are 'on and after' the deleted positions,
so you should use the iterator returned by the
erase() method. This is the iterator pointing
to the next valid position after the removal
of the entries.
For deleting the container in one of the
VectorContainer array entries, you can simply
assign the SmartPointer to zero.
seeds[27] = 0;
This will cause the reference count of the
VectorContainer to be decremented (and if
no other smart pointer was pointing to it,
the container will be destroyed).
Note that if you plan to reuse the location
27 later on, you could rather do
seeds[27] = NodeContainer::New();
That is, assign a freshly created container.
The previous container will still be destroyed,
but you will have the safety of having an empty
container available at the same position.
Out of curiosity,
Why do you want to isolate the nodes per Z slice ?
The FastMarching method is N-Dimensional, you could
simple have a unique NodeContainer holding all the
seed points of the image....
Regards,
Luis
--------------------------
Laurent Mundeleer wrote:
> Hi Luis,
>
> in fact I'd like to do both. The 128 elements are representing the z
> coordonate of my image volume.
> Brad allready send me elements of answer :
>
>> The VectorContainer provides a DeleteIndex method to remove an element
>
> from one entry in seeds. If you want to remove an entire container from
>
>> seeds[x], then that is up to you because it is just a standard array.
>> I suggest you convert seeds to look like this:
>>
>> std::vector< NodeContainer::Pointer > seeds;
>>
>> or
>>
>> std::set< NodeContainer::Pointer > seeds;
>>
>> Then there is no limit to the number of seeds and you get the STL
>
> container features to manage the structure.
>
>>
>> -Brad
>
>
> But I'm not quite familiar with STL so I'm still looking how I'll do to
> delete all a range of seeds, or a particular seed (found by a
> approximation of the x,y coordinates).
> For the moment it will be all the nodes for a z value, it will be easier.
>
> Thanks for the help
>
> Laurent
>
> Luis Ibanez wrote:
>
>>
>>
>> Hi Laurent,
>>
>> With:
>>
>> NodeContainer::Pointer seeds[128];
>>
>> You are declaring an array of 128
>> SmartPointers to:
>>
>> "VectorContainer< unsigned int, NodeType >".
>>
>> When you say that you want to delete some
>> elements from "seeds", do you mean that you
>> want to destroy one of the 128 entries in
>> this array of smart pointers ?
>>
>> or, do you mean that from one of those
>> 128 Containers you want to delete some
>> of its NodeType entries ?
>>
>>
>> Please let us know,
>>
>>
>> Thanks
>>
>>
>> Luis
>>
>>
>>
>>
>> --------------------------
>>
>> Laurent Mundeleer wrote:
>>
>>> in fact I think I didn't gave you enough information, here's some code :
>>> ...
>>>
>>> typedef itk::FastMarchingImageFilter<Image2DType, Image2DType>
>>> fastMarchingType;
>>> typedef fastMarchingType::NodeContainer NodeContainer;
>>> typedef fastMarchingType::NodeType NodeType;
>>>
>>> ...
>>> NodeContainer::Pointer seeds[128];
>>> ...
>>> void levelSetITK::addSeed(float *pos, float ratio)
>>> { typedef NodeType::IndexType IndexType;
>>> IndexType point;
>>>
>>> float ratio0 = ratio*0.969;
>>> float ratio1 = ratio*0.98;
>>>
>>> point[0] = static_cast<IndexType::IndexValueType>( pos[0]*ratio0 );
>>> point[1] = static_cast<IndexType::IndexValueType>( pos[1]*ratio1 );
>>> NodeType node;
>>>
>>> node.SetValue( -25.0 );
>>> node.SetIndex( point );
>>>
>>> int p = (int) pos[2];
>>> seeds[p]->InsertElement( nbreSeed[p], node );
>>> nbreSeed[p]++;
>>> }
>>>
>>> and I'd like to remove some element from seeds.
>>>
>>> Thanks
>>>
>>> Laurent
>>>
>>> Brad King wrote:
>>>
>>>> Laurent Mundeleer wrote:
>>>>
>>>>> Hi all,
>>>>>
>>>>> I can't figure how to remove an element anywhere in a
>>>>> VectorContainer (like erase(pos) in stl) ??
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> The class derives from std::vector, so the same methods should be
>>>> available. However, you should know that itk::VectorContainer is
>>>> used by itk::Image to manage memory for pixel buffers. It is not
>>>> intended to be used as a general-purpose container by user code.
>>>>
>>>> -Brad
>>>>
>>>>
>>>
>>
>>
>>
>>
>
>