ParaViewWeb JavaScript Code sample
From KitwarePublic
Jump to navigationJump to search
Creating a pipeline
<source lang="javascript">
/* Let’s start by creating a Cone object: */ var cone = paraview.Cone();
/* To get a full list of properties. just call the ListProperties method on the object */ alert("Properties list: " + cone.ListProperties());
/* Let's show the resolution property */ alert("Cone resolution: " + cone.getResolution());
/* You can increase the resolution as shown below. */ cone.setResolution(32);
/* Alternatively, we could have specified a value for resolution when creating the object. */ var cone2 = paraview.Cone( { Resolution:64 }); alert("Cone2 resolution: " + cone2.getResolution());
/* You can assign values to any number of properties during construction using keyword arguments. Let’s also change the center. */ alert("Cone center: " + cone.getCenter());
/* To asign an array value you can either do that */ cone.setCenter([1, 2, 3]); /* or do that */ cone2.setCenter(4, 5, 6);
/* Next, let’s apply a shrink filter to the cone: */ var shrinkFilter = paraview.Shrink( {Input:cone} );
/* At this point, if you are interested in getting some information about the output of the shrink filter, you can force it to update (which will also cause the execution of the cone source). For details about VTK's demand-driven pipeline model used by ParaView, see one of the VTK books. */ var dataInformation = paraview.GetDataInformation({proxy:shrinkFilter}); alert("Number of cells: " + dataInformation.NbCells); alert("Number of points: " + dataInformation.NbPoints); alert("Bounds: " + dataInformation.Bounds); alert("Extent: " + dataInformation.Extent); alert("Memory: " + dataInformation.Memory); alert("Type: " + dataInformation.Type);
/* We can pre-create a view with nice settings */ /* var activeView = paraview.CreateIfNeededRenderView(); */
/* Let's do the rendering */ paraview.Show( {proxy:shrinkFilter} );
/* in order to center object and rotation around this object */ paraview.ResetCamera(); var activeView = paraview.CreateIfNeededRenderView(); activeView.setCenterOfRotation(activeView.getCameraFocalPoint());
</source>
Representations and Views
<source lang="javascript">
/* Create a simple pipeline */ var sph = paraview.Sphere(); var elev = paraview.Elevation( {Input:sph} );
paraview.Show({proxy:elev}); paraview.Render();
/* Set the representation type of elev */ var activeView = paraview.CreateIfNeededRenderView();
/* Outline : 3 Wireframe : 1 Surface : 2 Surface with edge: 5 Points : 0 */ paraview.SetDisplayProperties( { proxy : elev , view : activeView, Representation : 1 } );
/* Let’s get some information about the output of the elevation filter. We want to color the representation by one of it’s arrays. Second array = Elevation. Interesting. Let’s use this one.*/ var ai = paraview.GetDataInformation({proxy:elev}).PointData.Arrays[1]; alert("Data array name: " + ai.Name);
/* What is its range? */ alert("Data array range: " + ai.Ranges);
/* To color the representation by an array, we just need to do */ var activeView = paraview.CreateIfNeededRenderView(); paraview.ColorBy({proxy:elev, view:activeView, arrayName:'Elevation', attribute:'Point'}); paraview.Render();
</source>
Loading file and time management
<source lang="javascript">
/* DO NOT FORGET to update the file path. It is a VTK sample data file */ var reader = paraview.OpenDataFile({filename:".../can.ex2"}); var activeView = paraview.CreateIfNeededRenderView(); paraview.Show();
var timeValues = reader.getTimestepValues(); alert("Time values: " + timeValues[0] + " ... " + timeValues[timeValues.length-1] + " (size: "+ timeValues.length + ")" );
/* Let’s be fancy and use a time annotation filter. This will show the current time value of the reader as text in the corner of the view.*/ var annTime = paraview.AnnotateTimeFilter({Input:reader}); paraview.Show({proxy:annTime});
activeView.setViewTime(timeValues[timeValues.length - 1]); time = activeView.getViewTime(); alert("New view time: " + time);
paraview.ResetCamera(); var activeView = paraview.CreateIfNeededRenderView(); activeView.setCenterOfRotation(activeView.getCameraFocalPoint());
</source>