• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

kstars

  • sources
  • kde-4.12
  • kdeedu
  • kstars
  • kstars
  • htmesh
SpatialEdge.cpp
Go to the documentation of this file.
1 //# Filename: SpatialEdge.cpp
2 //#
3 //# The SpatialEdge class is defined here.
4 //#
5 //# Author: Peter Z. Kunszt based on A. Szalay's code
6 //#
7 //# Date: October 15, 1998
8 //#
9 //# Copyright (C) 2000 Peter Z. Kunszt, Alex S. Szalay, Aniruddha R. Thakar
10 //# The Johns Hopkins University
11 //#
12 //# Modification History:
13 //#
14 //# Oct 18, 2001 : Dennis C. Dinge -- Replaced ValVec with std::vector
15 //#
16 
17 #include "SpatialEdge.h"
18 
19 // ===========================================================================
20 //
21 // Macro definitions for readability
22 //
23 // ===========================================================================
24 #define IV(x) tree_.nodes_[index].v_[(x)]
25 #define IW(x) tree_.nodes_[index].w_[(x)]
26 #define LAYER tree_.layers_[layerindex_]
27 
28 
29 // ===========================================================================
30 //
31 // Member functions for class SpatialEdge
32 //
33 // ===========================================================================
34 
36 //
37 SpatialEdge::SpatialEdge(SpatialIndex & tree, size_t layerindex) :
38  tree_(tree), layerindex_(layerindex) {
39 
40  edges_ = new Edge [LAYER.nEdge_ + 1];
41  lTab_ = new Edge* [LAYER.nVert_ * 6];
42 
43  // initialize lookup table, we depend on that NULL
44  for(size_t i = 0; i < LAYER.nVert_ * 6; i++)
45  lTab_[i] = NULL;
46 
47  // first vertex index for the vertices to be generated
48  index_ = LAYER.nVert_;
49 }
50 
51 
53 //
54 SpatialEdge::~SpatialEdge() {
55  delete[] edges_;
56  delete[] lTab_;
57 }
58 
60 // makeMidPoints: interface to this class. Set midpoints of every
61 // node in this layer.
62 void
63 SpatialEdge::makeMidPoints()
64 {
65  size_t c=0;
66  size_t index;
67 
68  // build up the new edges
69 
70  index = (size_t)LAYER.firstIndex_;
71  for(size_t i=0; i < LAYER.nNode_; i++,index++){
72  c = newEdge(c,index,0);
73  c = newEdge(c,index,1);
74  c = newEdge(c,index,2);
75  }
76 }
77 
78 
80 // newEdge: determines whether the edge em is already in the list. k
81 // is the label of the edge within the node Returns index of next
82 // edge, if not found, or returns same if it is already there. Also
83 // registers the midpoint in the node.
84 
85 size_t
86 SpatialEdge::newEdge(size_t emindex, size_t index, int k)
87 {
88  Edge *en, *em;
89  size_t swap;
90 
91  em = &edges_[emindex];
92 
93  switch (k) {
94  case 0:
95  em->start_ = IV(1);
96  em->end_ = IV(2);
97  break;
98  case 1:
99  em->start_ = IV(0);
100  em->end_ = IV(2);
101  break;
102  case 2:
103  em->start_ = IV(0);
104  em->end_ = IV(1);
105  break;
106  }
107 
108  // sort the vertices by increasing index
109 
110  if(em->start_ > em->end_) {
111  swap = em->start_;
112  em->start_ = em->end_;
113  em->end_ = swap;
114  }
115 
116  // check all previous edges for a match, return pointer if
117  // already present, log the midpoint with the new face as well
118 
119  if( (en=edgeMatch(em)) != NULL){
120  IW(k) = en->mid_;
121  return emindex;
122  }
123 
124 // this is a new edge, immediately process the midpoint,
125 // and save it with the nodes and the edge as well
126 
127  insertLookup(em);
128  IW(k) = getMidPoint(em);
129  em->mid_ = IW(k);
130  return ++emindex;
131 }
132 
133 
135 // insertLookup: insert the edge em into the lookup table.
136 // indexed by em->start_.
137 // Every vertex has at most 6 edges, so only
138 // that much lookup needs to be done.
139 void
140 SpatialEdge::insertLookup(Edge *em)
141 {
142 int j = 6 * em->start_;
143 int i;
144 
145 // do not loop beyond 6
146 
147  for(i=0; i<6; i++, j++)
148  if ( lTab_[j] == NULL ) {
149  lTab_[j] = em;
150  return;
151  }
152 }
153 
155 // edgeMatch: fast lookup using the first index em->start_.
156 // return pointer to edge if matches, null if not.
157 SpatialEdge::Edge *
158 SpatialEdge::edgeMatch(Edge *em)
159 {
160 int i = 6 * em->start_;
161 
162  while ( lTab_[i] != NULL ) {
163  if(em->end_ == lTab_[i]->end_ ) return lTab_[i];
164  i++;
165  }
166  return NULL;
167 }
168 
170 // getMidPoint: compute the midpoint of the edge using vector
171 // algebra and return its index in the vertex list
172 size_t
173 SpatialEdge::getMidPoint(Edge *em)
174 {
175  tree_.vertices_[index_] = tree_.vertices_[em->start_] +
176  tree_.vertices_[em->end_];
177  tree_.vertices_[index_].normalize();
178  return index_++;
179 }
SpatialIndex
The Spatial Index is a quad tree of spherical triangles.
Definition: SpatialIndex.h:59
RangeConvex::index_
const SpatialIndex * index_
Definition: RangeConvex.h:196
SpatialEdge::makeMidPoints
void makeMidPoints()
Definition: SpatialEdge.cpp:63
Edge
Definition: fitsimage.h:61
SpatialEdge.h
IV
#define IV(x)
Definition: SpatialEdge.cpp:24
SpatialEdge::~SpatialEdge
~SpatialEdge()
Definition: SpatialEdge.cpp:54
IW
#define IW(x)
Definition: SpatialEdge.cpp:25
LAYER
#define LAYER
Definition: SpatialEdge.cpp:26
SpatialEdge::SpatialEdge
SpatialEdge(SpatialIndex &tree, size_t layerindex)
Definition: SpatialEdge.cpp:37
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:36:21 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kstars

Skip menu "kstars"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal