<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="">
Hi,
<div class=""><br class="">
</div>
<div class="">I’m having some issues getting my remote rendering working. It all works perfectly fine with the the default cone from vtk (code from here:
<a href="https://github.com/dmreagan/vtk-remote-render" class="">https://github.com/dmreagan/vtk-remote-render</a> ), but when I adapt the code to use my own model with interpolation, I get the error:</div>
<div class=""><br class="">
</div>
<div class="">"WebSocket connection to '<a href="ws://localhost:1234/ws" class="">ws://localhost:1234/ws</a>' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED”</div>
<div class=""><br class="">
</div>
<div class="">I can see the serve side has rendered, but the client side is blank.</div>
<div class=""><br class="">
</div>
<div class="">My code is below, any help would be much appreciated!</div>
<div class=""><br class="">
</div>
<div class="">Many thanks,</div>
<div class="">Shruti</div>
<div class=""><br class="">
</div>
<div class="">
<div style="color: rgb(212, 212, 212); background-color: rgb(30, 30, 30); font-family: Menlo, Monaco, 'Courier New', monospace; line-height: 18px; white-space: pre;" class="">
<div class=""><span style="color: #569cd6;" class="">r</span><span style="color: #ce9178;" class="">"""</span></div>
<div class=""><span style="color: #ce9178;" class="">This module is a VTK Web server application.</span></div>
<div class=""><span style="color: #ce9178;" class="">The following command line illustrates how to use it::</span></div>
<br class="">
<div class=""><span style="color: #ce9178;" class="">$ vtkpython .../vtk_server.py</span></div>
<br class="">
<div class=""><span style="color: #ce9178;" class="">Any VTK Web executable script comes with a set of standard arguments that</span></div>
<div class=""><span style="color: #ce9178;" class="">can be overriden if need be::</span></div>
<div class=""><span style="color: #ce9178;" class="">--host localhost</span></div>
<div class=""><span style="color: #ce9178;" class="">Interface on which the HTTP server will listen.</span></div>
<br class="">
<div class=""><span style="color: #ce9178;" class="">--port 8080</span></div>
<div class=""><span style="color: #ce9178;" class="">Port number on which the HTTP server will listen.</span></div>
<br class="">
<div class=""><span style="color: #ce9178;" class="">--content /path-to-web-content/</span></div>
<div class=""><span style="color: #ce9178;" class="">Directory that you want to serve as static web content.</span></div>
<div class=""><span style="color: #ce9178;" class="">By default, this variable is empty which means that we rely on another server</span></div>
<div class=""><span style="color: #ce9178;" class="">to deliver the static content and the current process only focuses on the</span></div>
<div class=""><span style="color: #ce9178;" class="">WebSocket connectivity of clients.</span></div>
<br class="">
<div class=""><span style="color: #ce9178;" class="">--authKey wslink-secret</span></div>
<div class=""><span style="color: #ce9178;" class="">Secret key that should be provided by the client to allow it to make any</span></div>
<div class=""><span style="color: #ce9178;" class="">WebSocket communication. The client will assume if none is given that the</span></div>
<div class=""><span style="color: #ce9178;" class="">server expects "wslink-secret" as the secret key.</span></div>
<div class=""><span style="color: #ce9178;" class="">"""</span></div>
<br class="">
<div class=""><span style="color: #608b4e;" class=""># import to process args</span></div>
<div class=""><span style="color: #c586c0;" class="">import</span> sys</div>
<div class=""><span style="color: #c586c0;" class="">import</span> os</div>
<br class="">
<div class=""><span style="color: #608b4e;" class=""># import maths modules</span></div>
<div class=""><span style="color: #c586c0;" class="">import</span> numpy <span style="color: #c586c0;" class="">
as</span> np</div>
<div class=""><span style="color: #c586c0;" class="">from</span> scipy.interpolate
<span style="color: #c586c0;" class="">import</span> interp1d</div>
<div class=""><span style="color: #c586c0;" class="">from</span> scipy <span style="color: #c586c0;" class="">
import</span> interpolate</div>
<div class=""><span style="color: #c586c0;" class="">from</span> scipy <span style="color: #c586c0;" class="">
import</span> ndimage</div>
<div class=""><span style="color: #c586c0;" class="">from</span> ReadCSV <span style="color: #c586c0;" class="">
import</span> readcsv</div>
<div class=""><span style="color: #608b4e;" class=""># from Interpolation import *</span></div>
<br class="">
<div class=""><span style="color: #608b4e;" class=""># import vtk modules.</span></div>
<div class=""><span style="color: #c586c0;" class="">import</span> vtk</div>
<div class=""><span style="color: #c586c0;" class="">from</span> vtk.web <span style="color: #c586c0;" class="">
import</span> protocols</div>
<div class=""><span style="color: #c586c0;" class="">from</span> vtk.web <span style="color: #c586c0;" class="">
import</span> wslink <span style="color: #c586c0;" class="">as</span> vtk_wslink</div>
<div class=""><span style="color: #c586c0;" class="">from</span> wslink <span style="color: #c586c0;" class="">
import</span> server</div>
<br class="">
<div class=""><span style="color: #608b4e;" class=""># import utility modules</span></div>
<div class=""><span style="color: #c586c0;" class="">import</span> csv</div>
<div class=""><span style="color: #c586c0;" class="">import</span> time</div>
<br class="">
<br class="">
<div class=""><span style="color: #c586c0;" class="">try</span>:</div>
<div class=""><span style="color: #c586c0;" class="">import</span> argparse</div>
<div class=""><span style="color: #c586c0;" class="">except</span> <span style="color: #4ec9b0;" class="">
ImportError</span>:</div>
<div class=""><span style="color: #608b4e;" class=""># since Python 2.6 and earlier don't have argparse, we simply provide</span></div>
<div class=""><span style="color: #608b4e;" class=""># the source for the same as _argparse and we use it instead.</span></div>
<div class=""><span style="color: #c586c0;" class="">from</span> vtk.util <span style="color: #c586c0;" class="">
import</span> _argparse <span style="color: #c586c0;" class="">as</span> argparse</div>
<br class="">
<div class=""><span style="color: #608b4e;" class=""># =============================================================================</span></div>
<div class=""><span style="color: #608b4e;" class=""># Create custom ServerProtocol class to handle clients requests</span></div>
<div class=""><span style="color: #608b4e;" class=""># =============================================================================</span></div>
<br class="">
<div class=""><span style="color: #569cd6;" class="">class</span> <span style="color: #4ec9b0;" class="">
_WebCone</span>(<span style="color: #4ec9b0;" class="">vtk_wslink</span>.<span style="color: #4ec9b0;" class="">ServerProtocol</span>):</div>
<div class=""><span style="color: #c586c0;" class="">try</span>:</div>
<div class=""><span style="color: #608b4e;" class=""># Application configuration</span></div>
<div class="">view = <span style="color: #569cd6;" class="">None</span></div>
<div class="">authKey = <span style="color: #ce9178;" class="">"wslink-secret"</span></div>
<br class="">
<div class="">sensor_locations = [<span style="color: #b5cea8;" class="">21035</span>,
<span style="color: #b5cea8;" class="">20577</span>, <span style="color: #b5cea8;" class="">
19625</span>, <span style="color: #b5cea8;" class="">19121</span>, <span style="color: #b5cea8;" class="">
18110</span>, <span style="color: #b5cea8;" class="">17567</span>, <span style="color: #b5cea8;" class="">
16501</span>, <span style="color: #b5cea8;" class="">16495</span>, <span style="color: #b5cea8;" class="">
15942</span>, <span style="color: #b5cea8;" class="">15347</span>, <span style="color: #b5cea8;" class="">
15314</span>, <span style="color: #b5cea8;" class="">14658</span>, <span style="color: #b5cea8;" class="">
20506</span>, <span style="color: #b5cea8;" class="">20027</span>, <span style="color: #b5cea8;" class="">
19544</span>, <span style="color: #b5cea8;" class="">19044</span>, <span style="color: #b5cea8;" class="">
18546</span>, <span style="color: #b5cea8;" class="">18031</span>, <span style="color: #b5cea8;" class="">
16957</span>, <span style="color: #b5cea8;" class="">16416</span>, <span style="color: #b5cea8;" class="">
15851</span>, <span style="color: #b5cea8;" class="">14574</span>, <span style="color: #b5cea8;" class="">
13733</span>, <span style="color: #b5cea8;" class="">3424</span>, <span style="color: #b5cea8;" class="">
20501</span>, <span style="color: #b5cea8;" class="">19525</span>, <span style="color: #b5cea8;" class="">
19025</span>, <span style="color: #b5cea8;" class="">18527</span>, <span style="color: #b5cea8;" class="">
18013</span>, <span style="color: #b5cea8;" class="">17488</span>, <span style="color: #b5cea8;" class="">
16962</span>, <span style="color: #b5cea8;" class="">16427</span>, <span style="color: #b5cea8;" class="">
15233</span>, <span style="color: #b5cea8;" class="">14578</span>, <span style="color: #b5cea8;" class="">
13746</span>, <span style="color: #b5cea8;" class="">21726</span>, <span style="color: #b5cea8;" class="">
19982</span>, <span style="color: #b5cea8;" class="">18981</span>, <span style="color: #b5cea8;" class="">
18478</span>, <span style="color: #b5cea8;" class="">17427</span>, <span style="color: #b5cea8;" class="">
16902</span>, <span style="color: #b5cea8;" class="">16361</span>, <span style="color: #b5cea8;" class="">
15793</span>, <span style="color: #b5cea8;" class="">15188</span>, <span style="color: #b5cea8;" class="">
14536</span>, <span style="color: #b5cea8;" class="">13691</span>, <span style="color: #b5cea8;" class="">
3370</span>, <span style="color: #b5cea8;" class="">4899</span>, <span style="color: #b5cea8;" class="">
19446</span>, <span style="color: #b5cea8;" class="">18434</span>, <span style="color: #b5cea8;" class="">
17382</span>, <span style="color: #b5cea8;" class="">16856</span>, <span style="color: #b5cea8;" class="">
16310</span>, <span style="color: #b5cea8;" class="">15122</span>, <span style="color: #b5cea8;" class="">
14465</span>, <span style="color: #b5cea8;" class="">13599</span>, <span style="color: #b5cea8;" class="">
13609</span>, <span style="color: #b5cea8;" class="">3291</span>, <span style="color: #b5cea8;" class="">
4957</span>, <span style="color: #b5cea8;" class="">67</span>, <span style="color: #b5cea8;" class="">
19904</span>, <span style="color: #b5cea8;" class="">19910</span>, <span style="color: #b5cea8;" class="">
18905</span>, <span style="color: #b5cea8;" class="">18393</span>, <span style="color: #b5cea8;" class="">
17877</span>, <span style="color: #b5cea8;" class="">17353</span>, <span style="color: #b5cea8;" class="">
16816</span>, <span style="color: #b5cea8;" class="">15694</span>, <span style="color: #b5cea8;" class="">
15078</span>, <span style="color: #b5cea8;" class="">14423</span>, <span style="color: #b5cea8;" class="">
13547</span>, <span style="color: #b5cea8;" class="">3188</span>, <span style="color: #b5cea8;" class="">
19856</span>, <span style="color: #b5cea8;" class="">19363</span>, <span style="color: #b5cea8;" class="">
18864</span>, <span style="color: #b5cea8;" class="">17826</span>, <span style="color: #b5cea8;" class="">
17297</span>, <span style="color: #b5cea8;" class="">17304</span>, <span style="color: #b5cea8;" class="">
16763</span>, <span style="color: #b5cea8;" class="">16218</span>, <span style="color: #b5cea8;" class="">
15645</span>, <span style="color: #b5cea8;" class="">15036</span>, <span style="color: #b5cea8;" class="">
13503</span>, <span style="color: #b5cea8;" class="">3106</span>, <span style="color: #b5cea8;" class="">
19811</span>, <span style="color: #b5cea8;" class="">18812</span>, <span style="color: #b5cea8;" class="">
18816</span>, <span style="color: #b5cea8;" class="">17780</span>, <span style="color: #b5cea8;" class="">
17249</span>, <span style="color: #b5cea8;" class="">16714</span>, <span style="color: #b5cea8;" class="">
16169</span>, <span style="color: #b5cea8;" class="">15595</span>, <span style="color: #b5cea8;" class="">
14974</span>, <span style="color: #b5cea8;" class="">14314</span>, <span style="color: #b5cea8;" class="">
13405</span>, <span style="color: #b5cea8;" class="">21809</span>, <span style="color: #b5cea8;" class="">
19780</span>, <span style="color: #b5cea8;" class="">19282</span>, <span style="color: #b5cea8;" class="">
18260</span>, <span style="color: #b5cea8;" class="">17742</span>, <span style="color: #b5cea8;" class="">
16671</span>, <span style="color: #b5cea8;" class="">15547</span>, <span style="color: #b5cea8;" class="">
14924</span>, <span style="color: #b5cea8;" class="">14254</span>, <span style="color: #b5cea8;" class="">
2786</span>, <span style="color: #b5cea8;" class="">2128</span>, <span style="color: #b5cea8;" class="">
975</span>, <span style="color: #b5cea8;" class="">364</span>, <span style="color: #b5cea8;" class="">
19732</span>, <span style="color: #b5cea8;" class="">18732</span>, <span style="color: #b5cea8;" class="">
18214</span>, <span style="color: #b5cea8;" class="">17161</span>, <span style="color: #b5cea8;" class="">
16617</span>, <span style="color: #b5cea8;" class="">16069</span>, <span style="color: #b5cea8;" class="">
14873</span>, <span style="color: #b5cea8;" class="">13299</span>, <span style="color: #b5cea8;" class="">
2749</span>, <span style="color: #b5cea8;" class="">925</span>, <span style="color: #b5cea8;" class="">
320</span>, <span style="color: #b5cea8;" class="">866</span>, <span style="color: #b5cea8;" class="">
20624</span>, <span style="color: #b5cea8;" class="">20151</span>, <span style="color: #b5cea8;" class="">
19660</span>, <span style="color: #b5cea8;" class="">18656</span>, <span style="color: #b5cea8;" class="">
17626</span>, <span style="color: #b5cea8;" class="">16571</span>, <span style="color: #b5cea8;" class="">
16015</span>, <span style="color: #b5cea8;" class="">15436</span>, <span style="color: #b5cea8;" class="">
14153</span>, <span style="color: #b5cea8;" class="">13250</span>, <span style="color: #b5cea8;" class="">
2675</span>, <span style="color: #b5cea8;" class="">2009</span>, <span style="color: #b5cea8;" class="">
20658</span>, <span style="color: #b5cea8;" class="">20162</span>, <span style="color: #b5cea8;" class="">
19178</span>, <span style="color: #b5cea8;" class="">18174</span>, <span style="color: #b5cea8;" class="">
17650</span>, <span style="color: #b5cea8;" class="">16577</span>, <span style="color: #b5cea8;" class="">
15458</span>, <span style="color: #b5cea8;" class="">14822</span>, <span style="color: #b5cea8;" class="">
13236</span>, <span style="color: #b5cea8;" class="">2678</span>, <span style="color: #b5cea8;" class="">
2652</span>, <span style="color: #b5cea8;" class="">2634</span>]</div>
<br class="">
<div class="">sensor_pressures = readcsv(<span style="color: #ce9178;" class="">"S003_norm_walk.csv"</span>)</div>
<div class="">min_pressure = <span style="color: #b5cea8;" class="">0</span> <span style="color: #608b4e;" class="">
# Standard scale - min pressure reading</span></div>
<div class="">max_pressure = <span style="color: #b5cea8;" class="">1</span> <span style="color: #608b4e;" class="">
# Standard scale - max pressure reading</span></div>
<div class="">stl_filename = <span style="color: #ce9178;" class="">"newpivot.stl"</span></div>
<br class="">
<div class="">visualisationIndex = <span style="color: #b5cea8;" class="">0</span></div>
<div class="">allPressures = []</div>
<br class="">
<div class=""><span style="color: #569cd6;" class="">def</span> <span style="color: #dcdcaa;" class="">
initialize</span>(<span style="color: #9cdcfe;" class="">self</span>):</div>
<div class=""><span style="color: #569cd6;" class="">global</span> renderer, renderWindow, renderWindowInteractor, cone, mapper, actor</div>
<br class="">
<div class=""><span style="color: #608b4e;" class=""># Bring used components</span></div>
<div class=""><span style="color: #569cd6;" class="">self</span>.registerVtkWebProtocol(protocols.vtkWebMouseHandler())</div>
<div class=""><span style="color: #569cd6;" class="">self</span>.registerVtkWebProtocol(protocols.vtkWebViewPort())</div>
<div class=""><span style="color: #569cd6;" class="">self</span>.registerVtkWebProtocol(protocols.vtkWebViewPortImageDelivery())</div>
<div class=""><span style="color: #569cd6;" class="">self</span>.registerVtkWebProtocol(protocols.vtkWebViewPortGeometryDelivery())</div>
<br class="">
<div class=""><span style="color: #608b4e;" class=""># Update authentication key to use</span></div>
<div class=""><span style="color: #569cd6;" class="">self</span>.updateSecret(_WebCone.authKey)</div>
<br class="">
<div class=""><span style="color: #608b4e;" class=""># Create default pipeline (Only once for all the session)</span></div>
<div class=""><span style="color: #c586c0;" class="">if</span> <span style="color: #569cd6;" class="">
not</span> _WebCone.view:</div>
<div class=""><span style="color: #608b4e;" class=""># VTK specific code</span></div>
<div class="">reader = vtk.vtkSTLReader()</div>
<div class="">reader.SetFileName(_WebCone.stl_filename)</div>
<div class="">reader.Update() <span style="color: #608b4e;" class=""># This is necessary to have the data ready to read.</span></div>
<br class="">
<div class="">obj = reader.GetOutputDataObject(<span style="color: #b5cea8;" class="">0</span>)</div>
<br class="">
<div class="">lut = vtk.vtkLookupTable()</div>
<div class="">lut.SetTableRange(_WebCone.min_pressure, _WebCone.max_pressure)</div>
<div class="">lut.SetHueRange(<span style="color: #b5cea8;" class="">0.0</span>, <span style="color: #b5cea8;" class="">
0.9</span>)</div>
<div class="">lut.SetSaturationRange(<span style="color: #b5cea8;" class="">0.5</span>,
<span style="color: #b5cea8;" class="">1</span>)</div>
<div class="">lut.SetValueRange(<span style="color: #b5cea8;" class="">0.7</span>,
<span style="color: #b5cea8;" class="">1</span>)</div>
<div class="">lut.Build() </div>
<div class=""></div>
<div class="">renderer = vtk.vtkRenderer()</div>
<div class="">renderer.SetBackground(<span style="color: #b5cea8;" class="">.1</span>,
<span style="color: #b5cea8;" class="">.2</span>, <span style="color: #b5cea8;" class="">
.4</span>)</div>
<div class="">renderWindow = vtk.vtkRenderWindow()</div>
<div class="">renderWindow.AddRenderer(renderer)</div>
<br class="">
<div class="">renderWindowInteractor = vtk.vtkRenderWindowInteractor()</div>
<div class="">renderWindowInteractor.SetRenderWindow(renderWindow)</div>
<div class="">renderWindowInteractor.GetInteractorStyle().SetCurrentStyleToTrackballCamera()</div>
<br class="">
<div class="">obj = _WebCone.interpolate(<span style="color: #569cd6;" class="">self</span>, obj)</div>
<br class="">
<div class="">mapper = vtk.vtkPolyDataMapper()</div>
<div class="">mapper.SetInputDataObject(obj)</div>
<div class="">mapper.SetScalarRange(_WebCone.min_pressure, _WebCone.max_pressure)</div>
<div class="">mapper.SetLookupTable(lut)</div>
<br class="">
<div class="">actor = vtk.vtkActor()</div>
<div class="">actor.SetMapper(mapper)</div>
<br class="">
<div class=""><span style="color: #608b4e;" class=""># create the scalar_bar</span></div>
<div class="">scalar_bar = vtk.vtkScalarBarActor()</div>
<div class="">scalar_bar.SetOrientationToHorizontal()</div>
<div class="">scalar_bar.SetLookupTable(lut)</div>
<div class="">scalar_bar.SetTitle(<span style="color: #ce9178;" class="">"Scale"</span>)</div>
<div class="">scalar_bar.SetNumberOfLabels(<span style="color: #b5cea8;" class="">8</span>)</div>
<div class="">scalar_bar.GetTitleTextProperty().SetFontSize(<span style="color: #b5cea8;" class="">15</span>)</div>
<div class="">scalar_bar.GetLabelTextProperty().SetFontSize(<span style="color: #b5cea8;" class="">10</span>)</div>
<br class="">
<div class=""><span style="color: #608b4e;" class=""># create the scalar_bar_widget</span></div>
<div class="">scalar_bar_widget = vtk.vtkScalarBarWidget()</div>
<div class="">scalar_bar_widget.SetInteractor(renderWindowInteractor)</div>
<div class="">scalar_bar_widget.SetScalarBarActor(scalar_bar)</div>
<div class="">scalar_bar_widget.On()</div>
<br class="">
<div class="">renderer.AddActor(actor)</div>
<div class="">renderer.ResetCamera()</div>
<div class="">renderWindow.Render()</div>
<br class="">
<div class=""><span style="color: #608b4e;" class=""># VTK Web application specific</span></div>
<div class="">_WebCone.view = renderWindow</div>
<div class=""><span style="color: #569cd6;" class="">self</span>.getApplication().GetObjectIdMap().SetActiveObject(<span style="color: #ce9178;" class="">"VIEW"</span>, renderWindow)</div>
<br class="">
<br class="">
<div class=""><span style="color: #c586c0;" class="">for</span> index <span style="color: #569cd6;" class="">
in</span> <span style="color: #dcdcaa;" class="">range</span>(<span style="color: #b5cea8;" class="">1000</span>):</div>
<div class="">_WebCone.visualisationIndex = index</div>
<div class="">obj = _WebCone.interpolate(<span style="color: #569cd6;" class="">self</span>, obj)</div>
<div class="">renderWindow.Render()</div>
<div class="">time.sleep(<span style="color: #b5cea8;" class="">1</span>)</div>
<br class="">
<br class="">
<div class=""><span style="color: #569cd6;" class="">def</span> <span style="color: #dcdcaa;" class="">
interpolate</span>(<span style="color: #9cdcfe;" class="">self</span>, <span style="color: #9cdcfe;" class="">
obj</span>):</div>
<div class="">filename = <span style="color: #ce9178;" class="">"Points with coordinates.csv"</span></div>
<div class=""><span style="color: #9cdcfe;" class="">file</span> = <span style="color: #dcdcaa;" class="">
open</span>(filename, <span style="color: #ce9178;" class="">"r"</span>)</div>
<div class="">reader = csv.reader(<span style="color: #9cdcfe;" class="">file</span>,
<span style="color: #9cdcfe;" class="">delimiter</span>=<span style="color: #ce9178;" class="">";"</span>)</div>
<br class="">
<div class="">rownum = <span style="color: #b5cea8;" class="">0</span></div>
<div class="">values = []</div>
<br class="">
<div class=""><span style="color: #c586c0;" class="">for</span> row <span style="color: #569cd6;" class="">
in</span> reader:</div>
<div class=""><span style="color: #c586c0;" class="">if</span> rownum == <span style="color: #b5cea8;" class="">
0</span>:</div>
<div class="">rownum += <span style="color: #b5cea8;" class="">1</span></div>
<div class=""><span style="color: #c586c0;" class="">else</span>:</div>
<div class="">strrow = row</div>
<div class="">new = strrow[<span style="color: #b5cea8;" class="">0</span>].split(<span style="color: #ce9178;" class="">','</span>)</div>
<div class="">values.append(new)</div>
<div class="">rownum += <span style="color: #b5cea8;" class="">1</span></div>
<div class=""><span style="color: #9cdcfe;" class="">file</span>.close()</div>
<br class="">
<div class="">xi = []</div>
<div class="">yi = []</div>
<div class="">zi = []</div>
<br class="">
<div class=""><span style="color: #c586c0;" class="">for</span> value <span style="color: #569cd6;" class="">
in</span> values:</div>
<div class="">xi.append(value[<span style="color: #b5cea8;" class="">1</span>])</div>
<div class="">yi.append(value[<span style="color: #b5cea8;" class="">2</span>])</div>
<div class="">zi.append(value[<span style="color: #b5cea8;" class="">3</span>])</div>
<br class="">
<div class="">xfixed = []</div>
<div class="">yfixed = []</div>
<div class="">zfixed = []</div>
<div class=""><span style="color: #c586c0;" class="">for</span> value <span style="color: #569cd6;" class="">
in</span> xi:</div>
<div class="">xfixed.append(<span style="color: #4ec9b0;" class="">float</span>(value))</div>
<div class=""><span style="color: #c586c0;" class="">for</span> value <span style="color: #569cd6;" class="">
in</span> yi:</div>
<div class="">yfixed.append(<span style="color: #4ec9b0;" class="">float</span>(value))</div>
<div class=""><span style="color: #c586c0;" class="">for</span> value <span style="color: #569cd6;" class="">
in</span> zi:</div>
<div class="">zfixed.append(<span style="color: #4ec9b0;" class="">float</span>(value))</div>
<br class="">
<div class="">xpressures = []</div>
<div class="">ypressures = []</div>
<div class="">zpressures = []</div>
<div class=""><span style="color: #c586c0;" class="">for</span> sensor <span style="color: #569cd6;" class="">
in</span> _WebCone.sensor_locations:</div>
<div class="">xpressures.append(xfixed[sensor])</div>
<div class="">ypressures.append(yfixed[sensor])</div>
<div class="">zpressures.append(zfixed[sensor])</div>
<br class="">
<div class=""><span style="color: #c586c0;" class="">if</span> <span style="color: #dcdcaa;" class="">
len</span>(_WebCone.allPressures) == <span style="color: #b5cea8;" class="">0</span>:</div>
<div class=""><span style="color: #9cdcfe;" class="">file</span> = <span style="color: #dcdcaa;" class="">
open</span>(<span style="color: #ce9178;" class="">"S003_norm_walk.csv"</span>, <span style="color: #ce9178;" class="">
'r'</span>)</div>
<div class="">reader = csv.reader(<span style="color: #9cdcfe;" class="">file</span>,
<span style="color: #9cdcfe;" class="">delimiter</span>=<span style="color: #ce9178;" class="">';'</span>)</div>
<div class=""><span style="color: #c586c0;" class="">for</span> row <span style="color: #569cd6;" class="">
in</span> reader:</div>
<div class="">_WebCone.allPressures.append(row)</div>
<div class=""></div>
<div class=""><span style="color: #9cdcfe;" class="">file</span>.close()</div>
<br class="">
<div class="">values = []</div>
<div class="">new = _WebCone.allPressures[_WebCone.visualisationIndex][<span style="color: #b5cea8;" class="">0</span>].split(<span style="color: #ce9178;" class="">','</span>)</div>
<div class="">values.append(new)</div>
<div class="">pressures_new = values[<span style="color: #b5cea8;" class="">0</span>]</div>
<div class="">pressures = []</div>
<div class=""><span style="color: #c586c0;" class="">for</span> item <span style="color: #569cd6;" class="">
in</span> pressures_new[<span style="color: #b5cea8;" class="">1</span>:<span style="color: #b5cea8;" class="">145</span>]:</div>
<div class="">pressures.append(<span style="color: #4ec9b0;" class="">float</span>(item))</div>
<br class="">
<div class=""><span style="color: #608b4e;" class=""># Build vertex_pressures via interpolation</span></div>
<div class=""><span style="color: #608b4e;" class="">#GetNumberOfPoints gets the points that VTK has assigned to the map</span></div>
<div class=""><span style="color: #608b4e;" class="">#array of vz-vy-vz triplets</span></div>
<div class=""><span style="color: #608b4e;" class="">#what does line 45 return....</span></div>
<div class="">vertex_pressures = np.zeros(obj.GetNumberOfPoints())</div>
<br class="">
<div class=""><span style="color: #608b4e;" class=""># for i in range(0, len(sensor_locations)):</span></div>
<div class=""><span style="color: #608b4e;" class=""># p = pressures[i]</span></div>
<div class=""><span style="color: #608b4e;" class=""># vertex_pressures[sensor_locations[i]] = pressures[i]</span></div>
<div class=""><span style="color: #608b4e;" class="">#coord = np.array((xpressures,ypressures)).T</span></div>
<div class="">newcoord = np.array((xfixed,yfixed)).T</div>
<div class="">xpressures= np.array(xpressures)</div>
<div class="">ypressures= np.array(ypressures)</div>
<div class="">zpressures= np.array(zpressures)</div>
<div class="">xfixed =np.array(xfixed)</div>
<div class="">yfixed = np.array(yfixed)</div>
<div class="">zfixed = np.array(zfixed)</div>
<div class="">pressures = np.array(pressures)</div>
<div class=""></div>
<div class=""><span style="color: #608b4e;" class=""># RBF shiv interpolation</span></div>
<div class="">f = interpolate.Rbf(xpressures,ypressures,zpressures,pressures,<span style="color: #9cdcfe;" class="">function</span>=<span style="color: #ce9178;" class="">'cubic'</span>)</div>
<div class="">vertex_pressures = f(xfixed,yfixed,zfixed)</div>
<br class="">
<div class=""><span style="color: #608b4e;" class=""># This is an array that I am creating to store the heights of the points. I</span></div>
<div class=""><span style="color: #608b4e;" class=""># will use this as a scalar field on the 'obj' so that the lookup table can be</span></div>
<div class=""><span style="color: #608b4e;" class=""># used to color it. You could obviously make the array anything you wanted,</span></div>
<div class=""><span style="color: #608b4e;" class=""># such as x or y or squared distance from some other point, for instance.</span></div>
<div class="">pressures = vtk.vtkDoubleArray()</div>
<div class="">pressures.SetName(<span style="color: #ce9178;" class="">"Pressures"</span>)</div>
<br class="">
<div class=""><span style="color: #608b4e;" class=""># Loop through the points in the vtkPolyData and record the height in the</span></div>
<div class=""><span style="color: #608b4e;" class=""># 'heights' array.</span></div>
<div class=""><span style="color: #c586c0;" class="">for</span> i <span style="color: #569cd6;" class="">
in</span> <span style="color: #dcdcaa;" class="">range</span>(obj.GetNumberOfPoints()):</div>
<div class="">p = vertex_pressures[i]</div>
<div class="">pressures.InsertNextValue(p)</div>
<br class="">
<div class=""><span style="color: #608b4e;" class=""># Add this array to the point data as a scalar.</span></div>
<div class="">obj.GetPointData().SetScalars(pressures)</div>
<br class="">
<div class=""><span style="color: #c586c0;" class="">return</span> obj</div>
<br class="">
<div class=""><span style="color: #c586c0;" class="">except</span>:</div>
<div class=""><span style="color: #dcdcaa;" class="">print</span>(<span style="color: #ce9178;" class="">"Fuck, it's wrong!"</span>)</div>
<br class="">
<div class=""><span style="color: #608b4e;" class=""># =============================================================================</span></div>
<div class=""><span style="color: #608b4e;" class=""># Main: Parse args and start server</span></div>
<div class=""><span style="color: #608b4e;" class=""># =============================================================================</span></div>
<br class="">
<div class=""><span style="color: #c586c0;" class="">if</span> <span style="color: #9cdcfe;" class="">
__name__</span> == <span style="color: #ce9178;" class="">"__main__"</span>:</div>
<div class=""><span style="color: #608b4e;" class=""># Create argument parser</span></div>
<div class="">parser = argparse.ArgumentParser(<span style="color: #9cdcfe;" class="">description</span>=<span style="color: #ce9178;" class="">"VTK/Web Cone web-application"</span>)</div>
<br class="">
<div class=""><span style="color: #608b4e;" class=""># Add default arguments</span></div>
<div class="">server.add_arguments(parser)</div>
<br class="">
<div class=""><span style="color: #608b4e;" class=""># Extract arguments</span></div>
<div class="">args = parser.parse_args()</div>
<br class="">
<div class=""><span style="color: #608b4e;" class=""># Configure our current application</span></div>
<div class="">_WebCone.authKey = args.authKey</div>
<br class="">
<div class=""><span style="color: #608b4e;" class=""># Start server</span></div>
<div class="">server.start_webserver(<span style="color: #9cdcfe;" class="">options</span>=args,
<span style="color: #9cdcfe;" class="">protocol</span>=_WebCone)</div>
<br class="">
<br class="">
<div class=""><span style="color: #608b4e;" class=""># class vtkTimerCallback():</span></div>
<div class=""><span style="color: #608b4e;" class=""># def __init__(self, sensors_values, sensor_locations, obj):</span></div>
<div class=""><span style="color: #608b4e;" class=""># self.timer_count = 0</span></div>
<div class=""><span style="color: #608b4e;" class=""># self.changed = False</span></div>
<div class=""><span style="color: #608b4e;" class=""># self.sensors_values = sensors_values</span></div>
<div class=""><span style="color: #608b4e;" class=""># self.sensor_locations = sensor_locations</span></div>
<div class=""><span style="color: #608b4e;" class=""># self.obj = obj</span></div>
<br class="">
<div class=""><span style="color: #608b4e;" class=""># def execute(self, obj, x):</span></div>
<div class=""><span style="color: #608b4e;" class=""># self.changed = False</span></div>
<br class="">
<div class=""><span style="color: #608b4e;" class=""># filename = "Points with coordinates.csv"</span></div>
<div class=""><span style="color: #608b4e;" class=""># file = open(filename, "r")</span></div>
<div class=""><span style="color: #608b4e;" class=""># reader = csv.reader(file, delimiter=";")</span></div>
<br class="">
<div class=""><span style="color: #608b4e;" class=""># rownum = 0</span></div>
<div class=""><span style="color: #608b4e;" class=""># values = []</span></div>
<br class="">
<div class=""><span style="color: #608b4e;" class=""># for row in reader:</span></div>
<div class=""><span style="color: #608b4e;" class=""># if rownum == 0:</span></div>
<div class=""><span style="color: #608b4e;" class=""># rownum += 1</span></div>
<div class=""><span style="color: #608b4e;" class=""># else:</span></div>
<div class=""><span style="color: #608b4e;" class=""># strrow = row</span></div>
<div class=""><span style="color: #608b4e;" class=""># new = strrow[0].split(',')</span></div>
<div class=""><span style="color: #608b4e;" class=""># values.append(new)</span></div>
<div class=""><span style="color: #608b4e;" class=""># rownum += 1</span></div>
<div class=""><span style="color: #608b4e;" class=""># file.close()</span></div>
<br class="">
<div class=""><span style="color: #608b4e;" class=""># xi = []</span></div>
<div class=""><span style="color: #608b4e;" class=""># yi = []</span></div>
<div class=""><span style="color: #608b4e;" class=""># zi = []</span></div>
<br class="">
<div class=""><span style="color: #608b4e;" class=""># for value in values:</span></div>
<div class=""><span style="color: #608b4e;" class=""># xi.append(value[1])</span></div>
<div class=""><span style="color: #608b4e;" class=""># yi.append(value[2])</span></div>
<div class=""><span style="color: #608b4e;" class=""># zi.append(value[3])</span></div>
<br class="">
<div class=""><span style="color: #608b4e;" class=""># xfixed = []</span></div>
<div class=""><span style="color: #608b4e;" class=""># yfixed = []</span></div>
<div class=""><span style="color: #608b4e;" class=""># zfixed = []</span></div>
<div class=""><span style="color: #608b4e;" class=""># for value in xi:</span></div>
<div class=""><span style="color: #608b4e;" class=""># xfixed.append(float(value))</span></div>
<div class=""><span style="color: #608b4e;" class=""># for value in yi:</span></div>
<div class=""><span style="color: #608b4e;" class=""># yfixed.append(float(value))</span></div>
<div class=""><span style="color: #608b4e;" class=""># for value in zi:</span></div>
<div class=""><span style="color: #608b4e;" class=""># zfixed.append(float(value))</span></div>
<br class="">
<div class=""><span style="color: #608b4e;" class=""># xpressures = []</span></div>
<div class=""><span style="color: #608b4e;" class=""># ypressures = []</span></div>
<div class=""><span style="color: #608b4e;" class=""># zpressures = []</span></div>
<div class=""><span style="color: #608b4e;" class=""># for sensor in _WebCone.sensor_locations:</span></div>
<div class=""><span style="color: #608b4e;" class=""># xpressures.append(xfixed[sensor])</span></div>
<div class=""><span style="color: #608b4e;" class=""># ypressures.append(yfixed[sensor])</span></div>
<div class=""><span style="color: #608b4e;" class=""># zpressures.append(zfixed[sensor])</span></div>
<br class="">
<div class=""><span style="color: #608b4e;" class=""># if len(_WebCone.allPressures) == 0:</span></div>
<div class=""><span style="color: #608b4e;" class=""># file = open("S003_norm_walk.csv", 'r')</span></div>
<div class=""><span style="color: #608b4e;" class=""># reader = csv.reader(file, delimiter=';')</span></div>
<div class=""><span style="color: #608b4e;" class=""># for row in reader:</span></div>
<div class=""><span style="color: #608b4e;" class=""># _WebCone.allPressures.append(row)</span></div>
<div class=""></div>
<div class=""><span style="color: #608b4e;" class=""># file.close()</span></div>
<br class="">
<div class=""><span style="color: #608b4e;" class=""># values = []</span></div>
<div class=""><span style="color: #608b4e;" class=""># new = _WebCone.allPressures[_WebCone.visualisationIndex][0].split(',')</span></div>
<div class=""><span style="color: #608b4e;" class=""># values.append(new)</span></div>
<div class=""><span style="color: #608b4e;" class=""># pressures_new = values[0]</span></div>
<div class=""><span style="color: #608b4e;" class=""># pressures = []</span></div>
<div class=""><span style="color: #608b4e;" class=""># for item in pressures_new[1:145]:</span></div>
<div class=""><span style="color: #608b4e;" class=""># pressures.append(float(item))</span></div>
<br class="">
<div class=""><span style="color: #608b4e;" class=""># # Build vertex_pressures via interpolation</span></div>
<div class=""><span style="color: #608b4e;" class=""># #GetNumberOfPoints gets the points that VTK has assigned to the map</span></div>
<div class=""><span style="color: #608b4e;" class=""># #array of vz-vy-vz triplets</span></div>
<div class=""><span style="color: #608b4e;" class=""># #what does line 45 return....</span></div>
<div class=""><span style="color: #608b4e;" class=""># vertex_pressures = np.zeros(obj.GetNumberOfPoints())</span></div>
<br class="">
<div class=""><span style="color: #608b4e;" class=""># # for i in range(0, len(sensor_locations)):</span></div>
<div class=""><span style="color: #608b4e;" class=""># # p = pressures[i]</span></div>
<div class=""><span style="color: #608b4e;" class=""># # vertex_pressures[sensor_locations[i]] = pressures[i]</span></div>
<div class=""><span style="color: #608b4e;" class=""># coord = np.array((xpressures,ypressures)).T</span></div>
<div class=""><span style="color: #608b4e;" class=""># newcoord = np.array((xfixed,yfixed)).T</span></div>
<div class=""><span style="color: #608b4e;" class=""># xpressures= np.array(xpressures)</span></div>
<div class=""><span style="color: #608b4e;" class=""># ypressures= np.array(ypressures)</span></div>
<div class=""><span style="color: #608b4e;" class=""># zpressures= np.array(zpressures)</span></div>
<div class=""><span style="color: #608b4e;" class=""># xfixed =np.array(xfixed)</span></div>
<div class=""><span style="color: #608b4e;" class=""># yfixed = np.array(yfixed)</span></div>
<div class=""><span style="color: #608b4e;" class=""># zfixed = np.array(zfixed)</span></div>
<div class=""><span style="color: #608b4e;" class=""># pressures = np.array(pressures)</span></div>
<div class=""></div>
<div class=""><span style="color: #608b4e;" class=""># # RBF shiv interpolation</span></div>
<div class=""><span style="color: #608b4e;" class=""># f = interpolate.Rbf(xpressures,ypressures,zpressures,pressures,function='cubic')</span></div>
<div class=""><span style="color: #608b4e;" class=""># vertex_pressures = f(xfixed,yfixed,zfixed)</span></div>
<br class="">
<div class=""><span style="color: #608b4e;" class=""># # This is an array that I am creating to store the heights of the points. I</span></div>
<div class=""><span style="color: #608b4e;" class=""># # will use this as a scalar field on the 'obj' so that the lookup table can be</span></div>
<div class=""><span style="color: #608b4e;" class=""># # used to color it. You could obviously make the array anything you wanted,</span></div>
<div class=""><span style="color: #608b4e;" class=""># # such as x or y or squared distance from some other point, for instance.</span></div>
<div class=""><span style="color: #608b4e;" class=""># pressures = vtk.vtkDoubleArray()</span></div>
<div class=""><span style="color: #608b4e;" class=""># pressures.SetName("Pressures")</span></div>
<br class="">
<div class=""><span style="color: #608b4e;" class=""># # Loop through the points in the vtkPolyData and record the height in the</span></div>
<div class=""><span style="color: #608b4e;" class=""># # 'heights' array.</span></div>
<div class=""><span style="color: #608b4e;" class=""># for i in range(obj.GetNumberOfPoints()):</span></div>
<div class=""><span style="color: #608b4e;" class=""># p = vertex_pressures[i]</span></div>
<div class=""><span style="color: #608b4e;" class=""># pressures.InsertNextValue(p)</span></div>
<br class="">
<div class=""><span style="color: #608b4e;" class=""># # Add this array to the point data as a scalar.</span></div>
<div class=""><span style="color: #608b4e;" class=""># obj.GetPointData().SetScalars(pressures)</span></div>
<br class="">
<div class=""><span style="color: #608b4e;" class=""># # Visualization stuff ... you need to tell the mapper about the scalar field</span></div>
<div class=""><span style="color: #608b4e;" class=""># # and the lookup table. The rest of this is pretty standard stuff.</span></div>
<div class=""><span style="color: #608b4e;" class=""># mapper = vtk.vtkPolyDataMapper()</span></div>
<div class=""><span style="color: #608b4e;" class=""># mapper.SetInputDataObject(self.obj)</span></div>
<br class="">
<div class=""><span style="color: #608b4e;" class=""># iren = obj</span></div>
<div class=""><span style="color: #608b4e;" class=""># iren.GetRenderWindow().Render()</span></div>
<div class=""><span style="color: #608b4e;" class=""># self.timer_count += 1</span></div>
</div>
</div>
</body>
</html>