[vtkusers] SafeDownCast does not work properly
Utkarsh Ayachit
utkarsh.ayachit at kitware.com
Wed Aug 9 17:17:03 EDT 2017
Maximillian,
> *a downcast is required in order to convert a vtkPolyData object into a *
*Mesh object*
Not true. A downcast is required to convert a *pointer* of type vtkPolyData
to *pointer* of type Mesh, but it need not succeed i.e. return non-null.
The cast will only succeed if the the object pointed to via the vtkPolyData
pointer is indeed of type Mesh. vtkSTLReader will never create Mesh, it
will only create vtkPolyData. As a result you cannot "downcast" it to Mesh
with success.
> *why do dynamic_cast work just fine whereas SafeDownCast don‘t*
Hopefully the attached C++ code helps.
Utkarsh
On Wed, Aug 9, 2017 at 4:23 PM, Maximilian Weiherer <
weiherer.maximilian at gmx.de> wrote:
> Hi Utkarsh,
>
> as *Mesh* *is a* vtkPolyData, a downcast is required in order to convert
> a vtkPolyData object into a *Mesh* object. I still don’t know why
> SafeDownCast do not work properly. As far as I know, the parent class
> (vtkPolyData) must be downcasted to *Mesh*… . If a dynamic_cast is
> essentially the same as SafeDownCast, why do dynamic_cast work just fine
> whereas SafeDownCast don‘t?
>
> Best regards
> Maximilian
>
> *Von:* Utkarsh Ayachit [mailto:utkarsh.ayachit at kitware.com]
> *Gesendet:* Mittwoch, 9. August 2017 20:33
> *An:* Maximilian Weiherer <weiherer.maximilian at gmx.de>; ParaView <
> paraview at paraview.org>
>
> *Betreff:* Re: [vtkusers] SafeDownCast does not work properly
>
>
>
> Maximilian,
>
>
>
> That's not a reasonable expectation. Mesh **isa** vtkPolyData, and not
> vice-versa. Look at docs for dynamic_cast in C++. In spirit, SafeDownCast
> is essentially the same thing.
>
>
>
> Utkarsh
>
>
>
> On Wed, Aug 9, 2017 at 2:12 PM, Maximilian Weiherer <
> weiherer.maximilian at gmx.de> wrote:
>
> Hi Utkarsh,
>
>
>
> thanks for your reply. I created the custom mesh class in order to add
> some new functionality (e.g. a method to check whether a mesh intersects
> another mesh). The vtkPolyData object which should be casted is the output
> of a vtkSTLReader, i.e.
>
> Mesh* mesh = Mesh::SafeDownCast(reader->GetOutput()); // mesh always
> equals NULL
>
> Best regards
>
> Maximilian
>
>
>
> *Von:* Utkarsh Ayachit [mailto:utkarsh.ayachit at kitware.com]
> *Gesendet:* Mittwoch, 9. August 2017 17:53
> *An:* Maximilian Weiherer <weiherer.maximilian at gmx.de>
> *Cc:* vtk <vtkusers at vtk.org>
> *Betreff:* Re: [vtkusers] SafeDownCast does not work properly
>
>
>
> Maximilian,
>
>
>
> I am confused why any arbitrary vtkPolyData object would be castable to
> "Mesh". It will only return non-null, if it's is indeed created as a Mesh.
> Is it? Where's the "<vtkPolyData object>" coming from?
>
>
>
> Utkarsh
>
>
>
> On Wed, Aug 9, 2017 at 11:50 AM, Maximilian Weiherer <
> weiherer.maximilian at gmx.de> wrote:
>
> Hi all,
>
>
>
> I defined my own mesh class (named *Mesh*) by inheriting from
> vtkPolyData. Now I am struggling with the SafeDownCast method in order to
> cast a vtkPolyData object into a *Mesh* object. Whenever I am applying a
> SafeDownCast to a vtkPolyData object, NULL is returned.
>
>
>
> The *Mesh* class looks as follows:
>
>
>
> class Mesh : public vtkPolyData
>
> {
>
> public:
>
> static Mesh* New();
>
> vtkTypeMacro(Mesh, vtkPolyData);
>
> void PrintSelf(ostream& os, vtkIndent indent);
>
>
>
> protected:
>
> Mesh();
>
> ~Mesh();
>
> private:
>
> Mesh(const Mesh&); // Not implemented.
>
> void operator=(const Mesh&); // Not implemented.
>
> };
>
>
>
> …and this is the cast that does not work properly:
>
>
>
> Mesh* mesh = Mesh::SafeDownCast(<vtkPolyData object>); // mesh always
> equals NULL
>
>
>
> Any help would be appreciated. Thanks!
>
>
>
> Best regards
>
> Maximilian
>
>
>
> [image: Das Bild wurde vom Absender entfernt.]
> <https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient>
>
> Virenfrei. www.avast.com
> <https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient>
>
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/
> opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Search the list archives at: http://markmail.org/search/?q=vtkusers
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/vtkusers
>
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20170809/08076d94/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image001.jpg
Type: image/jpeg
Size: 350 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20170809/08076d94/attachment.jpg>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: code.cpp
Type: text/x-c++src
Size: 539 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20170809/08076d94/attachment.cpp>
More information about the vtkusers
mailing list