Can't create RasterElement object!

classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|

Can't create RasterElement object!

WestSun
I use following code in my plugin:


ModelResource<RasterElement> pResultCube(RasterUtilities::createRasterElement("D:\\K-Means.img",
           400, 300, INT1UBYTE));
   if (pResultCube.get() == NULL)
   {
           std::string msg = QObject::tr("A raster cube could not be created.").toStdString();
           pStep->finalize(Message::Failure, msg);
           if (pProgress != NULL)
           {
                   pProgress->updateProgress(msg, 0, ERRORS);
           }
           return false;
   }


Why the "pResultCube.get() == NULL" is true?

Reply | Threaded
Open this post in threaded view
|

Re: Can't create RasterElement object!

dadkins
Administrator
Does an element with that name already exist?
If so, createRasterElement will return NULL.


-----Original Message-----
From: WestSun [mailto:[hidden email]]
Sent: Wednesday, April 10, 2013 8:29 AM
To: [hidden email]
Subject: [Opticks-devs] Can't create RasterElement object!

I use following code in my plugin:

ModelResource<RasterElement>
pResultCube(RasterUtilities::createRasterElement("D:\\K-Means.img",
           400, 300, INT1UBYTE));
   if (pResultCube.get() == NULL)
   {
           std::string msg = QObject::tr("A raster cube could not be
created.").toStdString();
           pStep->finalize(Message::Failure, msg);
           if (pProgress != NULL)
           {
                   pProgress->updateProgress(msg, 0, ERRORS);
           }
           return false;
   }


Why the "pResultCube.get() == NULL" is true?





--
View this message in context:
http://opticks-devs.2021163.n4.nabble.com/Can-t-create-RasterElement-obj
ect-tp4652982.html
Sent from the opticks-devs mailing list archive at Nabble.com.

------------------------------------------------------------------------
------
Precog is a next-generation analytics platform capable of advanced
analytics on semi-structured data. The platform includes APIs for
building
apps and a phenomenal toolset for data science. Developers can use
our toolset for easy data analysis & visualization. Get a free account!
http://www2.precog.com/precogplatform/slashdotnewsletter
_______________________________________________
Opticks-devs mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/opticks-devs



This message and any enclosures are intended only for the addressee.  Please

notify the sender by email if you are not the intended recipient.  If you are

not the intended recipient, you may not use, copy, disclose, or distribute this

message or its contents or enclosures to any other person and any such actions

may be unlawful.  Ball reserves the right to monitor and review all messages

and enclosures sent to or from this email address.

------------------------------------------------------------------------------
Precog is a next-generation analytics platform capable of advanced
analytics on semi-structured data. The platform includes APIs for building
apps and a phenomenal toolset for data science. Developers can use
our toolset for easy data analysis & visualization. Get a free account!
http://www2.precog.com/precogplatform/slashdotnewsletter
_______________________________________________
Opticks-devs mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/opticks-devs
Reply | Threaded
Open this post in threaded view
|

Re: Can't create RasterElement object!

WestSun
This post was updated on .
Thanks for your reply.  you are right! I changed the name and get not NULL RasterElement any more
Reply | Threaded
Open this post in threaded view
|

Re: Can't create RasterElement object!

WestSun
In reply to this post by dadkins
I got another problom! I want add a PseudocolorLayer in the current view,  as the following code:

But the PseudocolorLayer has not been added in the View!(I can't see the new layer in the view)


ModelResource<RasterElement> pResultCube(RasterUtilities::createRasterElement(testName,
           pDescriptor->getRowCount(), pDescriptor->getColumnCount(), pDescriptor->getDataType()));
   if (pResultCube.get() == NULL)
   {
           std::string msg = QObject::tr("A raster cube could not be created.").toStdString();
           pStep->finalize(Message::Failure, msg);
           if (pProgress != NULL)
           {
                   pProgress->updateProgress(msg, 0, ERRORS);
           }
           return false;
   }

   unsigned int bytesPerElement=pDescriptor->getBytesPerElement();
   string dataFilename=findDataFile(pElement->getFilename());  
   unsigned int dataSize=pDescriptor->getRowCount()*pDescriptor->getColumnCount()*bytesPerElement;
   unsigned char* data=new unsigned char[dataSize];
   //Read data from file
   FILE *stream;
   if ((stream = fopen(dataFilename.c_str(), "r")) == NULL)
   {
           if (pProgress != NULL)
           {
                   pProgress->updateProgress(QObject::tr("Could not access the data file.").toStdString(), 100, ERRORS);
           }
           pStep->finalize(Message::Failure, QObject::tr("Could not access the data file.").toStdString());
           return false;
   }
   
   fread((void*)(data), 1,dataSize,stream);
   pResultCube->setRawData((void*)(data),true);
   
   PseudocolorLayer* pLayer = NULL;
   LayerList* pLayerList = pView->getLayerList();
   if (pLayerList != NULL)
   {
           pLayer = static_cast<PseudocolorLayer*>(pView->createLayer(PSEUDOCOLOR, pResultCube.get()));
   }
   INVARIANT(pLayer != NULL);

   int classCount = 6;
   pLayer->addInitializedClass(std::string("Indeterminate"), -1, ColorType(255, 255, 255), true);
   for (int i=0;i<classCount;i++)
   {
            int r=atoi(classValues[i*3].c_str());
                int g=atoi(classValues[i*3+1].c_str());
                int b=atoi(classValues[i*3+2].c_str());
            pLayer->addInitializedClass(classNames[i], i, ColorType(r, g, b), true);
   }

   if (pOutArgList != NULL)
   {
      pOutArgList->setPlugInArgValue("Layer", pLayer);
   }

Reply | Threaded
Open this post in threaded view
|

Re: Can't create RasterElement object!

dadkins
Administrator
I don't see anything wrong with the createLayer call.
We are doing something similar in QtCluster.cpp and
ConnectedComponents.cpp.

Are you sure your raster element's data is being set correctly?
Try displaying the element in a raster layer just to make sure.


-----Original Message-----
From: WestSun [mailto:[hidden email]]
Sent: Wednesday, April 10, 2013 11:31 AM
To: [hidden email]
Subject: Re: [Opticks-devs] Can't create RasterElement object!

I got another problom! I want add a PseudocolorLayer in the current
view,  as
the following code:

But the PseudocolorLayer has not been added in the View!(I can't see the
new
layer in the view)


ModelResource<RasterElement>
pResultCube(RasterUtilities::createRasterElement(testName,
           pDescriptor->getRowCount(), pDescriptor->getColumnCount(),
pDescriptor->getDataType()));
   if (pResultCube.get() == NULL)
   {
           std::string msg = QObject::tr("A raster cube could not be
created.").toStdString();
           pStep->finalize(Message::Failure, msg);
           if (pProgress != NULL)
           {
                   pProgress->updateProgress(msg, 0, ERRORS);
           }
           return false;
   }

   unsigned int bytesPerElement=pDescriptor->getBytesPerElement();
   string dataFilename=findDataFile(pElement->getFilename());  
   unsigned int
dataSize=pDescriptor->getRowCount()*pDescriptor->getColumnCount()*bytesP
erElement;
   unsigned char* data=new unsigned char[dataSize];
   //Read data from file
   FILE *stream;
   if ((stream = fopen(dataFilename.c_str(), "r")) == NULL)
   {
           if (pProgress != NULL)
           {
                   pProgress->updateProgress(QObject::tr("Could not
access the data
file.").toStdString(), 100, ERRORS);
           }
           pStep->finalize(Message::Failure, QObject::tr("Could not
access the data
file.").toStdString());
           return false;
   }
   
   fread((void*)(data), 1,dataSize,stream);
   pResultCube->setRawData((void*)(data),true);
   
   PseudocolorLayer* pLayer = NULL;
   LayerList* pLayerList = pView->getLayerList();
   if (pLayerList != NULL)
   {
           pLayer =
static_cast<PseudocolorLayer*>(pView->createLayer(PSEUDOCOLOR,
pResultCube.get()));
   }
   INVARIANT(pLayer != NULL);

   int classCount = 6;
   pLayer->addInitializedClass(std::string("Indeterminate"), -1,
ColorType(255, 255, 255), true);
   for (int i=0;i<classCount;i++)
   {
            int r=atoi(classValues[i*3].c_str());
                int g=atoi(classValues[i*3+1].c_str());
                int b=atoi(classValues[i*3+2].c_str());
            pLayer->addInitializedClass(classNames[i], i, ColorType(r,
g, b),
true);
   }

   if (pOutArgList != NULL)
   {
      pOutArgList->setPlugInArgValue("Layer", pLayer);
   }




--
View this message in context:
http://opticks-devs.2021163.n4.nabble.com/Can-t-create-RasterElement-obj
ect-tp4652982p4652985.html
Sent from the opticks-devs mailing list archive at Nabble.com.

------------------------------------------------------------------------
------
Precog is a next-generation analytics platform capable of advanced
analytics on semi-structured data. The platform includes APIs for
building
apps and a phenomenal toolset for data science. Developers can use
our toolset for easy data analysis & visualization. Get a free account!
http://www2.precog.com/precogplatform/slashdotnewsletter
_______________________________________________
Opticks-devs mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/opticks-devs



This message and any enclosures are intended only for the addressee.  Please

notify the sender by email if you are not the intended recipient.  If you are

not the intended recipient, you may not use, copy, disclose, or distribute this

message or its contents or enclosures to any other person and any such actions

may be unlawful.  Ball reserves the right to monitor and review all messages

and enclosures sent to or from this email address.

------------------------------------------------------------------------------
Precog is a next-generation analytics platform capable of advanced
analytics on semi-structured data. The platform includes APIs for building
apps and a phenomenal toolset for data science. Developers can use
our toolset for easy data analysis & visualization. Get a free account!
http://www2.precog.com/precogplatform/slashdotnewsletter
_______________________________________________
Opticks-devs mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/opticks-devs
Reply | Threaded
Open this post in threaded view
|

Re: Can't create RasterElement object!

tclarke
Administrator
Does the pseudocolor layer's element show up in the Elements tab of the
Session Manager? Does the pseudocolor layer show up in the Windows table
of the Session Manager? Is the visibility checkbox set? If the layer
shows up but you don't see anything, right click on it in the Session
Manager and select Convert then convert to a raster layer. You should be
able to mouse over values in the window and verify your data is set
correctly (or zoom in until the values appear as numbers)

-----Original Message-----
From: Adkins, Dustan [mailto:[hidden email]]
Sent: Wednesday, April 10, 2013 12:04 PM
To: [hidden email]
Subject: Re: [Opticks-devs] Can't create RasterElement object!

I don't see anything wrong with the createLayer call.
We are doing something similar in QtCluster.cpp and
ConnectedComponents.cpp.

Are you sure your raster element's data is being set correctly?
Try displaying the element in a raster layer just to make sure.


-----Original Message-----
From: WestSun [mailto:[hidden email]]
Sent: Wednesday, April 10, 2013 11:31 AM
To: [hidden email]
Subject: Re: [Opticks-devs] Can't create RasterElement object!

I got another problom! I want add a PseudocolorLayer in the current
view,  as
the following code:

But the PseudocolorLayer has not been added in the View!(I can't see the
new
layer in the view)


ModelResource<RasterElement>
pResultCube(RasterUtilities::createRasterElement(testName,
           pDescriptor->getRowCount(), pDescriptor->getColumnCount(),
pDescriptor->getDataType()));
   if (pResultCube.get() == NULL)
   {
           std::string msg = QObject::tr("A raster cube could not be
created.").toStdString();
           pStep->finalize(Message::Failure, msg);
           if (pProgress != NULL)
           {
                   pProgress->updateProgress(msg, 0, ERRORS);
           }
           return false;
   }

   unsigned int bytesPerElement=pDescriptor->getBytesPerElement();
   string dataFilename=findDataFile(pElement->getFilename());  
   unsigned int
dataSize=pDescriptor->getRowCount()*pDescriptor->getColumnCount()*bytesP
erElement;
   unsigned char* data=new unsigned char[dataSize];
   //Read data from file
   FILE *stream;
   if ((stream = fopen(dataFilename.c_str(), "r")) == NULL)
   {
           if (pProgress != NULL)
           {
                   pProgress->updateProgress(QObject::tr("Could not
access the data
file.").toStdString(), 100, ERRORS);
           }
           pStep->finalize(Message::Failure, QObject::tr("Could not
access the data
file.").toStdString());
           return false;
   }
   
   fread((void*)(data), 1,dataSize,stream);
   pResultCube->setRawData((void*)(data),true);
   
   PseudocolorLayer* pLayer = NULL;
   LayerList* pLayerList = pView->getLayerList();
   if (pLayerList != NULL)
   {
           pLayer =
static_cast<PseudocolorLayer*>(pView->createLayer(PSEUDOCOLOR,
pResultCube.get()));
   }
   INVARIANT(pLayer != NULL);

   int classCount = 6;
   pLayer->addInitializedClass(std::string("Indeterminate"), -1,
ColorType(255, 255, 255), true);
   for (int i=0;i<classCount;i++)
   {
            int r=atoi(classValues[i*3].c_str());
                int g=atoi(classValues[i*3+1].c_str());
                int b=atoi(classValues[i*3+2].c_str());
            pLayer->addInitializedClass(classNames[i], i, ColorType(r,
g, b),
true);
   }

   if (pOutArgList != NULL)
   {
      pOutArgList->setPlugInArgValue("Layer", pLayer);
   }




--
View this message in context:
http://opticks-devs.2021163.n4.nabble.com/Can-t-create-RasterElement-obj
ect-tp4652982p4652985.html
Sent from the opticks-devs mailing list archive at Nabble.com.

------------------------------------------------------------------------
------
Precog is a next-generation analytics platform capable of advanced
analytics on semi-structured data. The platform includes APIs for
building
apps and a phenomenal toolset for data science. Developers can use
our toolset for easy data analysis & visualization. Get a free account!
http://www2.precog.com/precogplatform/slashdotnewsletter
_______________________________________________
Opticks-devs mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/opticks-devs



This message and any enclosures are intended only for the addressee.
Please

notify the sender by email if you are not the intended recipient.  If
you are

not the intended recipient, you may not use, copy, disclose, or
distribute this

message or its contents or enclosures to any other person and any such
actions

may be unlawful.  Ball reserves the right to monitor and review all
messages

and enclosures sent to or from this email address.

------------------------------------------------------------------------
------
Precog is a next-generation analytics platform capable of advanced
analytics on semi-structured data. The platform includes APIs for
building
apps and a phenomenal toolset for data science. Developers can use
our toolset for easy data analysis & visualization. Get a free account!
http://www2.precog.com/precogplatform/slashdotnewsletter
_______________________________________________
Opticks-devs mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/opticks-devs



This message and any enclosures are intended only for the addressee.  Please

notify the sender by email if you are not the intended recipient.  If you are

not the intended recipient, you may not use, copy, disclose, or distribute this

message or its contents or enclosures to any other person and any such actions

may be unlawful.  Ball reserves the right to monitor and review all messages

and enclosures sent to or from this email address.

------------------------------------------------------------------------------
Precog is a next-generation analytics platform capable of advanced
analytics on semi-structured data. The platform includes APIs for building
apps and a phenomenal toolset for data science. Developers can use
our toolset for easy data analysis & visualization. Get a free account!
http://www2.precog.com/precogplatform/slashdotnewsletter
_______________________________________________
Opticks-devs mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/opticks-devs
Reply | Threaded
Open this post in threaded view
|

Re: Can't create RasterElement object!

WestSun
I add this code

pResultCube.release();


and can see the new layer.
Reply | Threaded
Open this post in threaded view
|

Re: Can't create RasterElement object!

Trevor Clarke
That makes sense. If you don't call release() then the RasterElement
will be deleted when the resource goes out of scope.

On 4/10/13, WestSun <[hidden email]> wrote:

> I add this code
>
> pResultCube.release();
>
>
> and can see the new layer.
>
>
>
> --
> View this message in context:
> http://opticks-devs.2021163.n4.nabble.com/Can-t-create-RasterElement-object-tp4652982p4652988.html
> Sent from the opticks-devs mailing list archive at Nabble.com.
>
> ------------------------------------------------------------------------------
> Precog is a next-generation analytics platform capable of advanced
> analytics on semi-structured data. The platform includes APIs for building
> apps and a phenomenal toolset for data science. Developers can use
> our toolset for easy data analysis & visualization. Get a free account!
> http://www2.precog.com/precogplatform/slashdotnewsletter
> _______________________________________________
> Opticks-devs mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/opticks-devs
>


--
Trevor R.H. Clarke
Computer Science House
Rochester Institute of Technology
[hidden email]
http://www.csh.rit.edu/~retrev/

------------------------------------------------------------------------------
Precog is a next-generation analytics platform capable of advanced
analytics on semi-structured data. The platform includes APIs for building
apps and a phenomenal toolset for data science. Developers can use
our toolset for easy data analysis & visualization. Get a free account!
http://www2.precog.com/precogplatform/slashdotnewsletter
_______________________________________________
Opticks-devs mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/opticks-devs
Reply | Threaded
Open this post in threaded view
|

Re: Can't create RasterElement object!

WestSun
This post was updated on .
Thanks! But another problom:
I want import my data file with special format as a PseudocolorLayer into current view, so I implement a importer derived from RasterElementImporterShell. I create a RasterElement in the

execute(PlugInArgList* pInArgList, PlugInArgList* pOutArgList)

 function (as the above code).

All things right when I loaded my file first time. But after I deleted the new PseudocolorLayer form workespace windows and reloaded the file. I got the error message "The data set currently exist.It may have already been imported" in "Import Options" Dialog. I can't load my file any more!

Has anything I forgot?

Reply | Threaded
Open this post in threaded view
|

Re: Can't create RasterElement object!

dadkins
Administrator
Check the Elements tab of session explorer. The element probably still
exists.
Something needs to delete it before you can re-import it; this is
normally done (for raster elements) when the last raster layer
displaying the element is destroyed.

-----Original Message-----
From: WestSun [mailto:[hidden email]]
Sent: Thursday, April 11, 2013 4:14 AM
To: [hidden email]
Subject: Re: [Opticks-devs] Can't create RasterElement object!

Thanks! But another problom:
I want import my data file with special format as a PseudocolorLayer
into
current view, so I implement a importer derived from
RasterElementImporterShell. I create a RasterElement in the
execute(PlugInArgList* pInArgList, PlugInArgList* pOutArgList)
 function (as the above code).

All things right when I loaded my file first time. But after I deleted
the
new PseudocolorLayer form workespace windows and reloaded the file. I
got
the error message "The data set currently exist.It may have already been
imported" in "Import Options" Dialog. I can't load my file any more!

Has something I forgot?





--
View this message in context:
http://opticks-devs.2021163.n4.nabble.com/Can-t-create-RasterElement-obj
ect-tp4652982p4652990.html
Sent from the opticks-devs mailing list archive at Nabble.com.

------------------------------------------------------------------------
------
Precog is a next-generation analytics platform capable of advanced
analytics on semi-structured data. The platform includes APIs for
building
apps and a phenomenal toolset for data science. Developers can use
our toolset for easy data analysis & visualization. Get a free account!
http://www2.precog.com/precogplatform/slashdotnewsletter
_______________________________________________
Opticks-devs mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/opticks-devs



This message and any enclosures are intended only for the addressee.  Please

notify the sender by email if you are not the intended recipient.  If you are

not the intended recipient, you may not use, copy, disclose, or distribute this

message or its contents or enclosures to any other person and any such actions

may be unlawful.  Ball reserves the right to monitor and review all messages

and enclosures sent to or from this email address.

------------------------------------------------------------------------------
Precog is a next-generation analytics platform capable of advanced
analytics on semi-structured data. The platform includes APIs for building
apps and a phenomenal toolset for data science. Developers can use
our toolset for easy data analysis & visualization. Get a free account!
http://www2.precog.com/precogplatform/slashdotnewsletter
_______________________________________________
Opticks-devs mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/opticks-devs
Reply | Threaded
Open this post in threaded view
|

Re: Can't create RasterElement object!

tclarke
Administrator
Since you are using RasterElementImporterShell your plug-in is probably
creating a RasterLayer and a PseudocolorLayer. Both share the same
RasterElement so both need to be deleted before the element is deleted.
To properly fix the issue, you need to re-implement
RasterElementImportShell::createView() instead of execute().
Alternately, you might be able to re-implement createRasterLayer() and
have it return NULL (you should be able to create the PseudocolorLayer
in this method and just return NULL...by default, the return value is
ignored)

-----Original Message-----
From: Adkins, Dustan [mailto:[hidden email]]
Sent: Thursday, April 11, 2013 8:41 AM
To: [hidden email]
Subject: Re: [Opticks-devs] Can't create RasterElement object!

Check the Elements tab of session explorer. The element probably still
exists.
Something needs to delete it before you can re-import it; this is
normally done (for raster elements) when the last raster layer
displaying the element is destroyed.

-----Original Message-----
From: WestSun [mailto:[hidden email]]
Sent: Thursday, April 11, 2013 4:14 AM
To: [hidden email]
Subject: Re: [Opticks-devs] Can't create RasterElement object!

Thanks! But another problom:
I want import my data file with special format as a PseudocolorLayer
into
current view, so I implement a importer derived from
RasterElementImporterShell. I create a RasterElement in the
execute(PlugInArgList* pInArgList, PlugInArgList* pOutArgList)
 function (as the above code).

All things right when I loaded my file first time. But after I deleted
the
new PseudocolorLayer form workespace windows and reloaded the file. I
got
the error message "The data set currently exist.It may have already been
imported" in "Import Options" Dialog. I can't load my file any more!

Has something I forgot?





--
View this message in context:
http://opticks-devs.2021163.n4.nabble.com/Can-t-create-RasterElement-obj
ect-tp4652982p4652990.html
Sent from the opticks-devs mailing list archive at Nabble.com.

------------------------------------------------------------------------
------
Precog is a next-generation analytics platform capable of advanced
analytics on semi-structured data. The platform includes APIs for
building
apps and a phenomenal toolset for data science. Developers can use
our toolset for easy data analysis & visualization. Get a free account!
http://www2.precog.com/precogplatform/slashdotnewsletter
_______________________________________________
Opticks-devs mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/opticks-devs



This message and any enclosures are intended only for the addressee.
Please

notify the sender by email if you are not the intended recipient.  If
you are

not the intended recipient, you may not use, copy, disclose, or
distribute this

message or its contents or enclosures to any other person and any such
actions

may be unlawful.  Ball reserves the right to monitor and review all
messages

and enclosures sent to or from this email address.

------------------------------------------------------------------------
------
Precog is a next-generation analytics platform capable of advanced
analytics on semi-structured data. The platform includes APIs for
building
apps and a phenomenal toolset for data science. Developers can use
our toolset for easy data analysis & visualization. Get a free account!
http://www2.precog.com/precogplatform/slashdotnewsletter
_______________________________________________
Opticks-devs mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/opticks-devs



This message and any enclosures are intended only for the addressee.  Please

notify the sender by email if you are not the intended recipient.  If you are

not the intended recipient, you may not use, copy, disclose, or distribute this

message or its contents or enclosures to any other person and any such actions

may be unlawful.  Ball reserves the right to monitor and review all messages

and enclosures sent to or from this email address.

------------------------------------------------------------------------------
Precog is a next-generation analytics platform capable of advanced
analytics on semi-structured data. The platform includes APIs for building
apps and a phenomenal toolset for data science. Developers can use
our toolset for easy data analysis & visualization. Get a free account!
http://www2.precog.com/precogplatform/slashdotnewsletter
_______________________________________________
Opticks-devs mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/opticks-devs
Reply | Threaded
Open this post in threaded view
|

Re: Can't create RasterElement object!

WestSun
Thanks!

I fixed the issue, by re-implement RasterElementImportShell::createView()