<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">
<div class="">Thanks Dan,</div>
<div class=""><br class="">
</div>
<div class="">I found the problem whilst cleaning up the code to send you a copy. Funny how that happens…</div>
<div class=""><br class="">
</div>
<div class="">It turned out to be an old </div>
<div class=""><br class="">
</div>
<div class="">int extent[6] = {0, 1, 0, 1, 0, 1}; </div>
<div class="">outInfo->Set<br class="">
         (vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT(), extent, 6);</div>
<div class=""><br class="">
</div>
<div class="">call in RequestInformation( … ) that was wrongly setting the extent to [0,1,0,1,0,1].</div>
<div class=""><br class="">
</div>
<div class="">Fixing that seemed to fix the problem of only 8 points showing up.</div>
<div class=""><br class="">
</div>
<div class="">I’ve been looking now at using the vtkRectilinearGrid class, I’ve set the X, Y and Z coordinates using the respective SetXCoordinates (vtkDataArray *) methods. But I can’t work out from the documentation how to enter my scalar data into this grid
 for use within paraview. </div>
<div class=""><br class="">
</div>
<div class="">Can you offer any advice on this? Or better point me to an example to learn from?</div>
<div class=""><br class="">
</div>
<div class="">Many thanks,</div>
<div class="">James</div>
<br class="">
<div>
<blockquote type="cite" class="">
<div class="">On 25 Aug 2015, at 15:39, Dan Lipsa <<a href="mailto:dan.lipsa@kitware.com" class="">dan.lipsa@kitware.com</a>> wrote:</div>
<br class="Apple-interchange-newline">
<div class="">
<div dir="ltr" class="">Hi James,
<div class="">I was used to the old style and it kind of made sense with the problem you are seeing, but you are right, setDimensions does not seem to be the problem.</div>
<div class=""><br class="">
</div>
<div class="">Is it any way I can get the code and a sample data so that I can run it through a debugger. I cannot see anything else in the code.</div>
<div class=""><br class="">
</div>
<div class="">Dan</div>
<div class=""><br class="">
<div class="gmail_extra"><br class="">
<div class="gmail_quote">On Tue, Aug 25, 2015 at 9:20 AM, James Furness <span dir="ltr" class="">
<<a href="mailto:pcxjf1@nottingham.ac.uk" target="_blank" onclick="window.open('https://mail.google.com/mail/?view=cm&tf=1&to=pcxjf1@nottingham.ac.uk&cc=&bcc=&su=&body=','_blank');return false;" class="">pcxjf1@nottingham.ac.uk</a>></span> wrote:<br class="">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div style="word-wrap:break-word" class="">Thanks for your advice, however it hasn’t quite solved my problem. 
<div class=""><br class="">
</div>
<div class=""><span class="">
<blockquote type="cite" class="">
<div dir="ltr" class="">
<div class="">You are missing image->SetDimensions() - that may be a reason why your scalar does not have all values.</div>
</div>
</blockquote>
<div class=""><br class="">
</div>
</span>
<div class="">The documentation marks vtkImageData::SetDimensions( ... ) as  depreciated, and instead vtkImageData::SetExtent( ... ) should be used. It remarks that SetDimension is equivalent to SetExtent(0, i-1, 0, j-1, 0, k-1).</div>
<div class=""><br class="">
</div>
<div class="">(( doc page -  <a href="http://www.vtk.org/doc/nightly/html/classvtkImageData.html#a42bc5faee908c50407e9d9ec97f74238" target="_blank" class="">http://www.vtk.org/doc/nightly/html/classvtkImageData.html#a42bc5faee908c50407e9d9ec97f74238</a> ))</div>
<div class=""><br class="">
</div>
<div class="">Regardless, I tried using SetDimensions in this way, and resulted in some nasty set-fault crashes. Whilst now 64 elements were found correctly, all passed the first 8 were memory junk. When I use SetExtent( … ) the information print on the image
 object happily reports dimensions of 4, 4, 4 as expected. So it seems this is set by SetExtent( … ).</div>
<span class="">
<div class=""><br class="">
</div>
<div class="">
<blockquote type="cite" class="">
<div dir="ltr" class="">
<div class="">vtkRectilinear grid is like an image data with variable extents and warped grid.</div>
</div>
</blockquote>
</div>
<div class=""><br class="">
</div>
</span>
<div class="">I’ll look into this class. It’s possible that I am mangling this reader by trying to shoehorn my problem into an inappropriate class at the moment. Thanks for pointing this out.</div>
<div class=""><br class="">
</div>
<div class="">Many thanks,</div>
<div class="">James</div>
<div class="">
<div class=""><br class="">
<div class="">
<blockquote type="cite" class="">
<div class="">On 24 Aug 2015, at 15:31, Dan Lipsa <<a href="mailto:dan.lipsa@kitware.com" target="_blank" onclick="window.open('https://mail.google.com/mail/?view=cm&tf=1&to=dan.lipsa@kitware.com&cc=&bcc=&su=&body=','_blank');return false;" class="">dan.lipsa@kitware.com</a>>
 wrote:</div>
<br class="">
<div class="">
<div dir="ltr" class="">James,
<div class="">You are missing image->SetDimensions() - that may be a reason why your scalar does not have all values.</div>
<div class=""><br class="">
</div>
<div class="">vtkRectilinear grid is like an image data with variable extents and warped grid.</div>
<div class=""><br class="">
</div>
</div>
<div class="gmail_extra"><br class="">
<div class="gmail_quote">On Fri, Aug 21, 2015 at 6:55 AM, James Furness <span dir="ltr" class="">
<<a href="mailto:pcxjf1@nottingham.ac.uk" target="_blank" onclick="window.open('https://mail.google.com/mail/?view=cm&tf=1&to=pcxjf1@nottingham.ac.uk&cc=&bcc=&su=&body=','_blank');return false;" class="">pcxjf1@nottingham.ac.uk</a>></span> wrote:<br class="">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hello,<br class="">
<br class="">
I have a program that will produce an output either in csv, or a binary format (which I have written and can alter).<br class="">
<br class="">
The data points are constructed by taking 3 vectors, and stepping at set intervals along these vectors to construct a 3D set of data. Ultimately there shouldn’t be a restriction on the three vectors, so the data may not be in a rectilinear array. But I’m leaving
 this for now and assuming the data is constructed from 3 orthogonal Axis aligned vectors to create a rectilinear structured grid. When I have a better grasp of preview readers I’ll update the reader to account for this. I guess it would require an unstructured
 data type to handle non-orthogonal grids?<br class="">
<br class="">
Also, the user is free to select what data they save from the program. This could be many fields, both vector and scalar quantities. What has been selected is stored in a header to the file, and known on reading. For my toy example I save only one scalar quantity.<br class="">
<br class="">
I’ve been trying to write a reader for paraview to import the binary files output. The csv format works ok, but the files can become large and it is a pain to have to construct the vector quantities from 3 scalars in each case, I want to avoid the user having
 to do this work. Another reason for writing a custom reader is to include additional information into the binary file for visualisation (e.g. the position of atoms, not a field quantity).<br class="">
<br class="">
With that background and reasoning I have managed to follow the documentation enough to read a basic test file, get the origin and point spacing, and read a single scalar quantity into a vtkDataArray owned by a vtkImageData object. Paraview picks this up seemingly
 correctly, with one flaw:<br class="">
<br class="">
It only takes 2 elements from each dimension, 0 and 1 displaying 8 elements in total. I am confident it has read the other values correctly as the Information tab reports “X extent 0 to 3” “X range: -1 to 1” (as expected) and similar for the other dimensions.
 If I view the data in spreadsheet layout the 8 values it has seem correct, but the others are missing.<br class="">
<br class="">
The code I am using in the reader’s RequestData(  ) function is added below.<br class="">
<br class="">
Does anyone know why this may be happening and how to fix it? Also, any advice on how I should structure the reader to handle the non-orthogonal data?<br class="">
<br class="">
Thanks for your time, and thank you for such a stellar program. The results paraview produces for this data is brilliant, hence my want to make it convenient for our users!<br class="">
<br class="">
Regards,<br class="">
James Furness<br class="">
<br class="">
<br class="">
CODE for RequestData( ) Method:<br class="">
———————————————————————<br class="">
<br class="">
int LondonReader::RequestData(<br class="">
        vtkInformation*,<br class="">
        vtkInformationVector**,<br class="">
        vtkInformationVector *outputVector)<br class="">
{<br class="">
    vtkWarningMacro("Requesting the data!");<br class="">
<br class="">
<br class="">
    ifstream finp;<br class="">
    finp.open(this->FileName, ios::in | ios::binary);<br class="">
<br class="">
    if (<a href="http://finp.is/" target="_blank" class="">finp.is</a>_open()) {<br class="">
        cerr << "File is open without problem!" << endl;<br class="">
    }   else    {<br class="">
        cerr << "File failed to open :(" << endl;<br class="">
        return 0;<br class="">
    }<br class="">
<br class="">
    // size of real numbers may not be 8. Check for this from file header<br class="">
    int realSize;<br class="">
    finp.read((char*)&realSize, sizeof(int));<br class="">
    if(realSize != 8)   {<br class="">
        cerr << "Not implimented yet!" << endl;<br class="">
        return 0;<br class="">
    }<br class="">
<br class="">
    // number of data fields<br class="">
    int nFields;<br class="">
    finp.read((char*)&nFields, sizeof(int));<br class="">
<br class="">
    vtkImageData* image = vtkImageData::GetData(outputVector);<br class="">
<br class="">
    // Read the dimensions of the grid and set the extent accordingly<br class="">
    int gridDim[3];<br class="">
    finp.read((char*)&gridDim, 3*sizeof(int));<br class="">
    int extent[6] = {0, gridDim[0]-1, 0, gridDim[1]-1, 0, gridDim[2]-1};<br class="">
    image->SetExtent(extent);<br class="">
<br class="">
<br class="">
    // Read the field names from the file<br class="">
    std::vector<std::string> fields;<br class="">
    std::string strBuf;<br class="">
    for (int i = 0; i < nFields; i++)   {<br class="">
        std::getline( finp, strBuf, '\0');<br class="">
        fields.push_back(strBuf);<br class="">
        cerr << "Printing Fields (" << i << "): " << fields[i] << endl;<br class="">
    }<br class="">
<br class="">
    // setup image for only one field for test case<br class="">
    image->AllocateScalars(VTK_FLOAT, 1);<br class="">
    vtkDataArray* scalars = image->GetPointData()->GetScalars();<br class="">
<br class="">
    // currently there is only one field 'rho'<br class="">
    scalars->SetName(fields[3].c_str());<br class="">
<br class="">
    double x, y, z, rho;<br class="">
    double oX, oY, oZ;      //origin coordinates<br class="">
    double sX, sY, sZ;      //spacing of points<br class="">
<br class="">
    for (vtkIdType itx = 0; itx < gridDim[0]; itx++)    {<br class="">
        for (vtkIdType ity = 0; ity < gridDim[1]; ity++)    {<br class="">
            for (vtkIdType itz = 0; itz < gridDim[2]; itz++)    {<br class="">
                finp.read((char*)&x, realSize);<br class="">
                finp.read((char*)&y, realSize);<br class="">
                finp.read((char*)&z, realSize);<br class="">
                finp.read((char*)&rho, realSize);<br class="">
<br class="">
                // Find and set the origin and spacing<br class="">
                if (itx == 0 && ity == 0 && itz == 0)   {<br class="">
                    image->SetOrigin(x, y, z);<br class="">
                    oX = x; oY = y; oZ = z;<br class="">
                }   else if (itx == 1 && ity == 0 && itz == 0)  {<br class="">
                    sX = x - oX;<br class="">
                }   else if (itx == 0 && ity == 1 && itz == 0)  {<br class="">
                    sY = y - oY;<br class="">
                }   else if (itx == 0 && ity == 0 && itz == 1)  {<br class="">
                    sZ = z - oZ;<br class="">
                }<br class="">
                //check correct read.<br class="">
                cerr << x << "," << y << "," << z << "," << rho << ", at " << itx*(gridDim[1]*gridDim[2]) + ity*gridDim[2] + itz << endl;<br class="">
<br class="">
                //add value<br class="">
                scalars->SetTuple1(itx*gridDim[1]*gridDim[2] + ity*gridDim[2] + itz,<br class="">
                        rho);<br class="">
            }<br class="">
        }<br class="">
    }<br class="">
<br class="">
    image->SetSpacing(sX, sY, sZ);<br class="">
<br class="">
    image->Print(cerr);<br class="">
<br class="">
    return 1;<br class="">
}<br class="">
<br class="">
<br class="">
<br class="">
<br class="">
<br class="">
This message and any attachment are intended solely for the addressee<br class="">
and may contain confidential information. If you have received this<br class="">
message in error, please send it back to me, and immediately delete it.<br class="">
<br class="">
Please do not use, copy or disclose the information contained in this<br class="">
message or in any attachment.  Any views or opinions expressed by the<br class="">
author of this email do not necessarily reflect the views of the<br class="">
University of Nottingham.<br class="">
<br class="">
This message has been checked for viruses but the contents of an<br class="">
attachment may still contain software viruses which could damage your<br class="">
computer system, you are advised to perform your own checks. Email<br class="">
communications with the University of Nottingham may be monitored as<br class="">
permitted by UK legislation.<br class="">
<br class="">
_______________________________________________<br class="">
Powered by <a href="http://www.kitware.com/" rel="noreferrer" target="_blank" class="">
www.kitware.com</a><br class="">
<br class="">
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" rel="noreferrer" target="_blank" class="">
http://www.kitware.com/opensource/opensource.html</a><br class="">
<br class="">
Please keep messages on-topic and check the ParaView Wiki at: <a href="http://paraview.org/Wiki/ParaView" rel="noreferrer" target="_blank" class="">
http://paraview.org/Wiki/ParaView</a><br class="">
<br class="">
Search the list archives at: <a href="http://markmail.org/search/?q=ParaView" rel="noreferrer" target="_blank" class="">
http://markmail.org/search/?q=ParaView</a><br class="">
<br class="">
Follow this link to subscribe/unsubscribe:<br class="">
<a href="http://public.kitware.com/mailman/listinfo/paraview" rel="noreferrer" target="_blank" class="">http://public.kitware.com/mailman/listinfo/paraview</a><br class="">
</blockquote>
</div>
<br class="">
</div>
</div>
</blockquote>
</div>
<br class="">
</div>
</div>
</div>
<div class="">
<div class="">
<pre class="">This message and any attachment are intended solely for the addressee
and may contain confidential information. If you have received this
message in error, please send it back to me, and immediately delete it. 

Please do not use, copy or disclose the information contained in this
message or in any attachment.  Any views or opinions expressed by the
author of this email do not necessarily reflect the views of the
University of Nottingham.

This message has been checked for viruses but the contents of an
attachment may still contain software viruses which could damage your
computer system, you are advised to perform your own checks. Email
communications with the University of Nottingham may be monitored as
permitted by UK legislation.
</pre>
</div>
</div>
</div>
</blockquote>
</div>
<br class="">
</div>
</div>
</div>
</div>
</blockquote>
</div>
<br class="">
<PRE>


This message and any attachment are intended solely for the addressee
and may contain confidential information. If you have received this
message in error, please send it back to me, and immediately delete it. 

Please do not use, copy or disclose the information contained in this
message or in any attachment.  Any views or opinions expressed by the
author of this email do not necessarily reflect the views of the
University of Nottingham.

This message has been checked for viruses but the contents of an
attachment may still contain software viruses which could damage your
computer system, you are advised to perform your own checks. Email
communications with the University of Nottingham may be monitored as
permitted by UK legislation.
</PRE></body>
</html>