Skip to content

Commit

Permalink
Deploying to gh-pages from @ 8c01bdf 🚀
Browse files Browse the repository at this point in the history
  • Loading branch information
leavauchier committed Mar 13, 2024
1 parent 3a2967e commit 8ca5c4d
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions _modules/myria3d/pctl/transforms/transforms.html
Original file line number Diff line number Diff line change
Expand Up @@ -192,16 +192,19 @@ <h1>Source code for myria3d.pctl.transforms.transforms</h1><div class="highlight
<span class="k">return</span> <span class="n">data</span></div>


<span class="k">def</span> <span class="nf">subsample_data</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">num_nodes</span><span class="p">,</span> <span class="n">choice</span><span class="p">):</span>
<span class="k">def</span> <span class="nf">subsample_data</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">num_nodes</span><span class="p">,</span> <span class="n">choice</span><span class="p">:</span> <span class="n">torch</span><span class="o">.</span><span class="n">Tensor</span><span class="p">):</span>
<span class="c1"># TODO: get num_nodes from data.num_nodes instead to simplify signature</span>
<span class="n">out_nodes</span> <span class="o">=</span> <span class="n">torch</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">choice</span><span class="p">)</span> <span class="k">if</span> <span class="n">choice</span><span class="o">.</span><span class="n">dtype</span> <span class="o">==</span> <span class="n">torch</span><span class="o">.</span><span class="n">bool</span> <span class="k">else</span> <span class="n">choice</span><span class="o">.</span><span class="n">size</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
<span class="k">for</span> <span class="n">key</span><span class="p">,</span> <span class="n">item</span> <span class="ow">in</span> <span class="n">data</span><span class="p">:</span>
<span class="k">if</span> <span class="n">key</span> <span class="o">==</span> <span class="s2">&quot;num_nodes&quot;</span><span class="p">:</span>
<span class="n">data</span><span class="o">.</span><span class="n">num_nodes</span> <span class="o">=</span> <span class="n">choice</span><span class="o">.</span><span class="n">size</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
<span class="n">data</span><span class="o">.</span><span class="n">num_nodes</span> <span class="o">=</span> <span class="n">out_nodes</span>
<span class="k">elif</span> <span class="n">key</span> <span class="ow">in</span> <span class="p">[</span><span class="s2">&quot;copies&quot;</span><span class="p">,</span> <span class="s2">&quot;idx_in_original_cloud&quot;</span><span class="p">]:</span>
<span class="c1"># Do not subsample copies of the original point cloud or indices of the original points</span>
<span class="c1"># contained in the patch</span>
<span class="k">continue</span>
<span class="k">elif</span> <span class="nb">bool</span><span class="p">(</span><span class="n">re</span><span class="o">.</span><span class="n">search</span><span class="p">(</span><span class="s2">&quot;edge&quot;</span><span class="p">,</span> <span class="n">key</span><span class="p">)):</span>
<span class="k">continue</span>
<span class="k">elif</span> <span class="n">torch</span><span class="o">.</span><span class="n">is_tensor</span><span class="p">(</span><span class="n">item</span><span class="p">)</span> <span class="ow">and</span> <span class="n">item</span><span class="o">.</span><span class="n">size</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span> <span class="o">==</span> <span class="n">num_nodes</span> <span class="ow">and</span> <span class="n">item</span><span class="o">.</span><span class="n">size</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span> <span class="o">!=</span> <span class="mi">1</span><span class="p">:</span>
<span class="n">data</span><span class="p">[</span><span class="n">key</span><span class="p">]</span> <span class="o">=</span> <span class="n">item</span><span class="p">[</span><span class="n">choice</span><span class="p">]</span>
<span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">item</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">)</span> <span class="ow">and</span> <span class="n">item</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="n">num_nodes</span> <span class="ow">and</span> <span class="n">item</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">!=</span> <span class="mi">1</span><span class="p">:</span>
<span class="k">elif</span> <span class="n">torch</span><span class="o">.</span><span class="n">is_tensor</span><span class="p">(</span><span class="n">item</span><span class="p">)</span> <span class="ow">and</span> <span class="n">item</span><span class="o">.</span><span class="n">size</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span> <span class="o">==</span> <span class="n">num_nodes</span><span class="p">:</span>
<span class="n">data</span><span class="p">[</span><span class="n">key</span><span class="p">]</span> <span class="o">=</span> <span class="n">item</span><span class="p">[</span><span class="n">choice</span><span class="p">]</span>

<span class="k">return</span> <span class="n">data</span>
Expand Down Expand Up @@ -402,6 +405,10 @@ <h1>Source code for myria3d.pctl.transforms.transforms</h1><div class="highlight
<span class="k">if</span> <span class="n">points_to_drop</span><span class="o">.</span><span class="n">sum</span><span class="p">()</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
<span class="n">points_to_keep</span> <span class="o">=</span> <span class="n">torch</span><span class="o">.</span><span class="n">logical_not</span><span class="p">(</span><span class="n">points_to_drop</span><span class="p">)</span>
<span class="n">data</span> <span class="o">=</span> <span class="n">subsample_data</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">num_nodes</span><span class="o">=</span><span class="n">data</span><span class="o">.</span><span class="n">num_nodes</span><span class="p">,</span> <span class="n">choice</span><span class="o">=</span><span class="n">points_to_keep</span><span class="p">)</span>
<span class="c1"># Here we also subsample these idx since we do not need to interpolate these points back</span>
<span class="c1"># It supposes that DropPointsByClass is run before copying the original point cloud</span>
<span class="k">if</span> <span class="s2">&quot;idx_in_original_cloud&quot;</span> <span class="ow">in</span> <span class="n">data</span><span class="p">:</span>
<span class="n">data</span><span class="o">.</span><span class="n">idx_in_original_cloud</span> <span class="o">=</span> <span class="n">data</span><span class="o">.</span><span class="n">idx_in_original_cloud</span><span class="p">[</span><span class="n">points_to_keep</span><span class="o">.</span><span class="n">numpy</span><span class="p">()]</span>

<span class="k">return</span> <span class="n">data</span></div>
</pre></div>
Expand Down

0 comments on commit 8ca5c4d

Please sign in to comment.