[Insight-users] Fiter's Update(- : ImageToMesh filter always re-executing

Luis Ibanez luis . ibanez at kitware . com
Sun, 22 Jun 2003 13:26:48 -0400


Hi Georges,

Thanks for sending the header of your filter.

Your observation revealed a bug in the way
the ImageToMesh filter is checking for the
need of recomputing the filter.

It comes down to the fact that the itkMesh
and the itkImage use different representation
for Regions.

In the Mesh, regions are simply enumerated,
while in images the region is indicated with
a starting index and a size.

The pipeline negociations have been well tunned
for images, but not extensively tested for meshes.

In order to solve the problem, several methods
where added to the PointSet class (which is the
base class of the itkMesh).
http://www . itk . org/Insight/Doxygen/html/classitk_1_1PointSet . html

These new methods are

    SetBufferedRegion( const RegionType & r );
    SetRequestedRegion( const RegionType & r );
    GetRequestedRegion()

With these methods being availabe, it is now
possible in your filter to specify that the
output Mesh has a buffered region equal to the
requested reqion.

Please do the following:

In the "GenerateData()" method of your filter,
at the end of the method, add the line

  mesh->SetBufferedRegion( mesh->GetRequestedRegion() );

where "mesh" is the output of your filter.
You may get it through dynamic_cast of this->GetOutput();



With this additional line, the pipeline will
know that the current buffered region of the
mesh is the same region that was requested in
the most recent Update(), and hence, subsequent
Update() calls will not need to re-execute the
GenerateData() method.

In order to get these two new methods of the
PointSet class you willl have to update your
cvs checkout. (check the dashboard before doing
this...)


Please give it a try to adding this line in
the GenerateData() method of your ImageToMesh
filter and let us know if you run into any
problem.



Thanks



    Luis



------------------------------
Georges Le Goualher wrote:
> 
> Hi Luis,
> 
> This is the filter header. Hope this help.
> 
> Many thanks,
> 
> Georges
> 
> 
> ------------------------------------------------------------------------
> 
> 
> #ifndef __myfilterfilter_h
> #define __myfilterfilter_h
> 
> #include <itkImage.h>
> #include <itkImageToMeshFilter.h>
> 
> #include "fdg.h"
> 
> 
> namespace mz
> {
> class MyfilterParam {
>  public :
>  MyfilterParam () {
>    defaults();
>  }
>  /// Gives the default values for the parameters
>  void defaults() {
>   doZ       = true; 
>   doD       = true; 
>   hD        = 1; 
>   oFactor   = 1.8; 
>   oSNL = 6;
>   oSRM = 1;
>   agp.defaults();
>  }
>  /// Load parameters from a file. If any error occurs, default values are provided. 
>  void loadParam(const char * fname);
>  /// Save parameters in a file.
>  void saveParam(const char * fname);
>  /// Output stream
>  friend std::ostream & operator << (std::ostream &, MyfilterParam &);
>  /// Input stream
>  friend std::istream & operator >> (std::istream &, MyfilterParam &);
>  // Parameters list : 
>  /// doZ
>  bool  doZ;
>  /// D
>  bool  doD;
>  /// hD
>  int   hD; 
>  /** factor 
>  */
>  float oFactor ;
>  /// Min 
>  int   oSNL ;
>  /// Re
>  int   oSRM ;
>  /// Class
>  FdMGParam agp;
> };
> 
> 
> 
> /// My filter
> /**
> */
> template < class TInputImage, class TOutputMesh >
> class ITK_EXPORT MyfilterFilter : public itk::ImageToMeshFilter< TInputImage, TOutputMesh > 
> {
> public: 
>    /** Standard class typedefs. */
>    typedef MyfilterFilter  Self;
>    typedef itk::ImageToMeshFilter < TInputImage, TOutputMesh > Superclass;
>    typedef itk::SmartPointer<Self>  Pointer;
>    typedef itk::SmartPointer<const Self>  ConstPointer;
> 
>    /** Some input Image related typedefs. */
>    typedef  TInputImage ImputImageType;
>    typedef typename ImputImageType::PixelType PixelType;
>    typedef typename ImputImageType::IndexType IndexType;
> 
>    /** Some output component image related typedefs. */
>    typedef unsigned long LPixelType ;
>    typedef itk::Image<LPixelType,2 > LImageType ;
> 
>  
>    /** Some typedefs associated with the output mesh. */
>    typedef TOutputMesh OutputMeshType;
>    typedef typename OutputMeshType::PointType        PointType;
>    typedef typename OutputMeshType::Pointer          OutputMeshPointer;
>    typedef typename OutputMeshType::PointsContainer  PointsContainer; 
>    typedef typename OutputMeshType::PointIdentifier  PointIdentifier; 
>    typedef typename PointsContainer::Pointer         PointsContainerPointer;
>    typedef typename PointsContainer::Iterator        PointsContainerIterator;
>    typedef typename OutputMeshType::PointDataContainer PointDataContainer; 
>    typedef typename PointDataContainer::Pointer      PointDataContainerPointer;
>    typedef typename PointDataContainer::Iterator     PointDataContainerIterator;
> 
>    
>    /** Run-time type information (and related methods). */
>    itkTypeMacro(MeshToImageMoFilter , itk::MeshToImageFilter );
> 
>    /** Method for creation through the object factory.  */
>    itkNewMacro(Self);
> 
>    /** SetCaImage **/
>    void SetCaImage(const InputImageType *inputImg){
>       SetInput (0, inputImg) ;
>    }
>    
>    /** SetBaCaImage   **/
>    void SetBaCa(const InputImageType *inputBa){
>       SetInput (1, inputBa) ;
>    }
> 
>    /** Get co image **/
>    LImageType * GetCoImage() { return _lImg;}
> 
>    /** The main function **/
>    virtual void GenerateData();
>    
>    /** Input requested region  **/
>    virtual void GenerateInputRequestedRegion();
> 
>    
> 
> protected:
>    MyfilterFilter ();
>    ~MyfilterFilter  (){}
>    void PrintSelf(std::ostream& os, itk::Indent indent) const;
>    // I N T E R N A L   F U N C T I O N S
>    // To be used only by derived classes
>    
>    /** pre
>    */
>    void pre();
>    
>    /** w
>     */
>    void w();
> 
>    /** sB
>     */
>    int sB ();
> 
>    /** mS
>     */
>    int mS ();
> 
>    /** create output mesh
>     */
>    void createOuputMesh ();
> 
>    /// Get filter parameters
>    MyfilterParam getParam(){
>       return _fdp;
>    }
>    /// Set object parameters
>    void setParam(MyfilterParam & fdp){
>       _fdp = fdp;
>    }
> 
> private:
> 
>    MyfilterFilter (const MyfilterFilter &); //purposely not implemented
>    void operator=(const MyfilterFilter &); //purposely not implemented
> 
> 
>   // Main parameters are stored in a separate class MyfilterParam
>    MyfilterParam _fdp;
> 
>    typename TInputImage::Pointer _baseImg;
>    typename LImageType::Pointer _lImg;
> 
>    std::vector< std::set<unsigned long> > _n;
>    std::vector< int > _fS; 
>    std::vector< float > _fC; 
>    unsigned short _mCC; 
>    float _fSM; 
>    std::vector<short> _fob; 
>    std::vector<float> _fiCo;
>    
>       
> }; // of class MyfilterFilter
> 
> } // namespace mz
> 
> #ifndef ITK_MANUAL_INSTANTIATION
> #include "myfilterfilter.hxx"
> #endif
> 
> #endif// __myfilterfilter_h
> 
> 
> 
> ------------------------------------------------------------------------
> 
> 
> 
> 
> On Thursday, June 12, 2003, at 03:46 PM, Luis Ibanez wrote:
> 
>>
>> Hi Georges,
>>
>> Your understanding of the pipeline is correct.
>> The GenerateData() method shouldn't be invoked
>> if the input, nor the filter parameters have
>> changed.
>>
>> Could you please give us more details on the
>> way you wrote your filter ?
>>
>> What are the types of the inputs and outputs ?
>>
>> Are you using the Set/Get macros for setting
>> the filter parameters ?
>>
>> If you post the header file of the filter,
>> that could help us to figure out what's wrong.
>>
>>
>> Thanks
>>
>>
>>    Luis
>>
>>
>> ------------------------------
>>
>> Georges Le Goualher wrote:
>>
>>> Hi all,
>>> I've written an itk filter and have the following problem:
>>> the GenerateData() method is called each time
>>> I call the Update() method even if the entries did not changed
>>> between two successive calls.
>>> I understand the normal behavior for a filter is to not
>>> do anything when called a second time on the same
>>> inputs.
>>> Can someone explain what is the code that control
>>> this behaviour?
>>> Thanks,
>>> Georges
>>> ---------------------------------------------------------------------
>>> Georges Le Goualher
>>> Ingenieur de Recherche / Research Engineer
>>> Mauna Kea Technologies, Paris
>>> www.maunakeatech.com
>>> tel: 33 1 48 24 24 96
>>> fax: 33 1 48 24 12 18
>>> ---------------------------------------------------------------------
>>> _______________________________________________
>>> Insight-users mailing list
>>> Insight-users at www . itk . org
>>> http://www . itk . org/mailman/listinfo/insight-users
>>
>>
>>
>>
>> _______________________________________________
>> Insight-users mailing list
>> Insight-users at www . itk . org
>> http://www . itk . org/mailman/listinfo/insight-users
>>
>>
> ---------------------------------------------------------------------
> Georges Le Goualher
> Ingenieur de Recherche / Research Engineer
> Mauna Kea Technologies, Paris
> www.maunakeatech.com
> tel: 33 1 48 24 24 96
> fax: 33 1 48 24 12 18
> ---------------------------------------------------------------------