[Insight-users] Re: help on how to add new element to itk

Luis Ibanez luis.ibanez at kitware.com
Thu, 08 Jan 2004 11:50:20 -0500


Hi Luzhong,

Yes, you can add classes to your local copy
of ITK without any permision.

Just have to follow the ITK coding standards.

I tryed compiling the classes that you kindly
sent but unfortuantely the file

          itkFEMElement2DC0LQ.h

was missing from your email.

Could you please send it ?

---

About your code:


     > using namespace std;
     > using namespace itk;
     > using namespace fem;


Please *NEVER, NEVER, NEVER*  do that.

Opening the namespace with "using namespace"
defeats the whole purpose of having namespaces.
It is like having secure doors only to leave
them open.

Please use the full specification of the
namespaces, like


  itk::fem::FEMElement<>
  std::cout << "I'm not lazy" << std::endl;


If the typenames start being too long,
use "typdef" and define aliases for the
types.

   typedef itk::fem::FEMElemet<>   ElemType;




Regards,


    Luis


------------------
luzhong yin wrote:

> Hi, Luis
> 
> Thanks for your reply.
> 
> In fact, the program is very simple, almost the same
> one as the original code. I basically use them to test
> whether I can freely add any component without any
> permision. 
> 
> Luzhong Yin
> 
> 
> Head file for the class is as follows,
> 
> #ifndef __itkFEMElement2DC0LQM_h
> #define __itkFEMElement2DC0LQM_h
> 
> #include "itkFEMElement2DC0LQ.h"
> #include "itkFEMElement2DMembrane.h"
> 
> namespace itk {
> namespace fem {
> 
> /**
>  * \class Element2DC0LQM
>  * \brief 4-noded finite element class in 2D space for
> linear elasticity problem
>  */
> class Element2DC0LQM : public
> Element2DMembrane<Element2DC0LQ>
> {
> FEM_CLASS(Element2DC0LQM,Element2DMembrane<Element2DC0LQ>)
> public:
> 
>   HANDLE_ELEMENT_LOADS();
> 
>   /**
>    * Default constructor only clears the internal
> storage
>    */
>   Element2DC0LQM();
> 
>   /**
>    * Construct an element by specifying pointers to
>    * 4 points and a material.
>    */
>   Element2DC0LQM(
>       NodeIDType n1_, 
>       NodeIDType n2_,
>       NodeIDType n3_,
>       NodeIDType n4_,
>       Material::ConstPointer p_ );
> 
> }; // class Element2DC0LQM
> 
> FEM_CLASS_INIT(Element2DC0LQM)
> 
> }} // end namespace itk::fem
> 
> #endif  // #ifndef __itkFEMElement2DC0LQM_h
> 
> 
> The test program is as follows:
> 
> #include "itkFEMElement2DC0LQM.h"
> #include "itkFEMElementBase.h"
> 
> //#include "itkFEM.h"
> 
> #include <iostream>
> 
> using namespace std;
> using namespace itk;
> using namespace fem;
> 
> //
> int main(int, char *[])
> {
>     Node::Pointer n0,n1,n2,n3;
>     Element::VectorType pt(2);
> 
>     n0=Node::New();
>     pt[0]=0.;
>     pt[1]=0.;
>     n0->SetCoordinates(pt);
> 
>     n1=Node::New();
>     pt[0]=1.;
>     pt[1]=1.;
>     n1->SetCoordinates(pt);
> 
>     n2=Node::New();
>     pt[0]=3.;
>     pt[1]=2.;
>     n2->SetCoordinates(pt);
> 
>     n3=Node::New();
>     pt[0]=0.;
>     pt[1]=3.;
>     n3->SetCoordinates(pt);
> 
>     MaterialLinearElasticity::Pointer m;
>     m=MaterialLinearElasticity::New();
>     m->GN=0;
>     m->E=30000.0;
>     m->A=0.02;
>     m->I=0.004;
> 
>     Element2DC0LQM::Pointer e0 =
> Element2DC0LQM::New();
> 
>     e0->GN=0;
>     e0->SetNode(0, &*n0);
>     e0->SetNode(1, &*n1);
>     e0->SetNode(2, &*n2);
>     e0->SetNode(3, &*n3);
>    
> e0->m_mat=dynamic_cast<MaterialLinearElasticity*>(&*m);
> 
>     Element::MatrixType D, Me;
> 
>     e0->GetMassMatrix(Me);
>     e0->GetMaterialMatrix(D);
>     cout << "Mass matrix: " << endl << Me << endl;
>     cout << "Material matrix: " << endl << D << endl;
>     cout << "#dof per node = " <<
> e0->GetNumberOfDegreesOfFreedomPerNode() << endl;
> 
> #ifndef FEM_USE_SMART_POINTERS
>     delete e0;
>     delete m;
>     delete n0;
>     delete n1;
>     delete n2;
>     delete n3;
> #endif
>     
>     std::cout << "Test PASSED!\n";
>     return EXIT_SUCCESS;
> }
> 
> 
> 
> 
> --- Luis Ibanez <luis.ibanez at kitware.com> wrote:
> 
>>Hi Luzhong,
>>
>>The errors that you are getting are produced by the
>>linker. They indicate that the class Element2DC0LQM
>>is missing methods such as
>>
>>     CLID()
>>
>>This seems to indicate that your new FEM class is
>>missing the macro:
>>
>>          FEM_ABSTRACT_CLASS()
>>
>>or the macro
>>
>>          FEM_CLASS()
>>
>>Please look at the file
>>
>>   
>>
> 
> Insight/Code/Numerics/FEM/itkFEMElement2DC0LinearLine.h
> 
>>for an example on how the macro should be used.
>>
>>or if you prefer, post the code of the header file
>>of your class and the code of the example file
>>test1.cxx  to the users-list.
>>
>>
>>Regards,
>>
>>
>>     Luis
>>
>>
>>
>>------------------------
>>luzhong yin wrote:
>>
>>>Dear Luis Ibanez,
>>>
>>>Recently, I am trying to learn about how to use
>>
>>itk. I
>>
>>>encounter some compile problem when I try to add
>>
>>some
>>
>>>new finite element class to itk. What I have done
>>
>>is:
>>
>>>First, I downloaded InsightToolkit-1.4.0.zip to my
>>>computer and then compiled it and made the binary
>>
>>code
>>
>>>available for all folds.
>>>
>>>Then I code a new class of finite element under
>>
>>the
>>
>>>framework of itk. That is, the element class
>>
>>Inherits
>>
>>>all the necessary part from itk. The files for the
>>>element class is in a local fold. I also wrote a
>>
>>small
>>
>>>testing problem for the new element in the same
>>
>>fold.
>>
>>>But I got some compile errors:
>>>
>>>test1.cxx
>>>Linking...
>>>test1.obj : error LNK2001: unresolved external
>>
>>symbol
>>
>>>"public: static int __cdecl
>>>itk::fem::Element2DC0LQM::CLID(void)"
>>>(?CLID at Element2DC0LQM at fem at itk at  at SAHXZ)
>>>test1.obj : error LNK2001: unresolved external
>>
>>symbol
>>
>>>"public: __thiscall
>>>itk::fem::Element2DC0LQM::Element2DC0LQM(void)"
>>>(??0Element2DC0LQM at fem at itk at  at QAE at XZ)
>>>Debug/test1.exe : fatal error LNK1120: 2
>>
>>unresolved
>>
>>>externals
>>>Error executing link.exe.
>>>
>>>What do those errors mean? It means that I cann't
>>
>>do
>>
>>>that way to add some new element to itk? I use
>>
>>VC++
>>
>>>6.0.
>>>
>>>
>>>Thank you very much.
>>>Luzhong
>>> 
>>>
>>>
>>>
>>>__________________________________
>>>Do you Yahoo!?
>>>Yahoo! Hotjobs: Enter the "Signing Bonus"
>>
>>Sweepstakes
>>
>>>http://hotjobs.sweepstakes.yahoo.com/signingbonus
>>>
>>
>>
>>
> 
> 
> __________________________________
> Do you Yahoo!?
> Yahoo! Hotjobs: Enter the "Signing Bonus" Sweepstakes
> http://hotjobs.sweepstakes.yahoo.com/signingbonus
>