File: CarveHelper.cpp

package info (click to toggle)
pymol 3.1.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 74,084 kB
  • sloc: cpp: 482,660; python: 89,328; ansic: 29,512; javascript: 6,792; sh: 84; makefile: 25
file content (73 lines) | stat: -rw-r--r-- 1,778 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/**
 * @file
 * Isosurface carving
 *
 * (c) 2020 Schrodinger, Inc.
 */

#include "CarveHelper.h"
#include "Map.h"

/**
 * Positive cutoff value keeps triangles within the cutoff radius (a single
 * vertex outside the radius will discard the triangle). A negative cutoff value
 * inverts the criteria (discards triangle if all vertices are within -cutoff).
 *
 * @param cutoff Cutoff for inclusion (if positive) or exclusion (if negative)
 * @param vertices Flat vertex array
 * @param n_vertices Vertex count
 */
CarveHelper::CarveHelper(PyMOLGlobals* G, float cutoff, const float* vertices,
    std::size_t n_vertices)
    : m_cutoff(cutoff)
    , m_vertices(vertices)
{
  if (cutoff < 0) {
    m_cutoff = -cutoff;
    m_avoid_flag = true;
  }

  m_voxelmap.reset(MapNew(G, -m_cutoff, vertices, n_vertices, nullptr));
}

/**
 * True if the given vertex is within the (positive) cutoff radius of any atom
 */
bool CarveHelper::is_within(const float* v) const
{
  for (const auto j : MapEIter(*m_voxelmap, v)) {
    if (within3f(m_vertices + 3 * j, v, m_cutoff)) {
      return true;
    }
  }

  return false;
}

/**
 * True if the given triangle should be excluded
 */
bool CarveHelper::is_excluded(
    const float* v0, const float* v1, const float* v2) const
{
  bool within = is_within(v0) && is_within(v1) && is_within(v2);
  return m_avoid_flag ? within : !within;
}

/**
 * True if the given line should be excluded
 */
bool CarveHelper::is_excluded(const float* v0, const float* v1) const
{
  bool within = is_within(v0) && is_within(v1);
  return m_avoid_flag ? within : !within;
}

/**
 * True if the given vertex should be excluded
 */
bool CarveHelper::is_excluded(const float* v0) const
{
  bool within = is_within(v0);
  return m_avoid_flag ? within : !within;
}