#include <TreeSearch.h>
Public Member Functions | |
clTree * | NextTree () |
Returns the next tree matching this search's criteria. | |
void | StartOver () |
Starts the tree search over. | |
clTreeSearch (clTreePopulation *p_oTreePop, clPlot *p_oPlot) | |
Constructor. | |
~clTreeSearch () | |
Destructor. | |
Protected Member Functions | |
clTree * | FindNextDHTree () |
Optimized for finding trees where only distance and height are specified. | |
clTree * | FindNextTSTree () |
Optimized for finding trees where only type and species are specified. | |
clTree * | FindNextTTree () |
Optimized for finding trees where only type is specified. | |
clTree * | FindNextAllTree () |
Sets up the object to find all trees. | |
clTree * | FindFirstDHTree () |
Finds the first tree in a distance/height search. | |
clTree * | FindFirstTSTree () |
Finds the first tree in a type/species search. | |
clTree * | FindFirstTTree () |
Finds the first tree in a type search. | |
clTree * | FindFirstAllTree () |
Finds the first tree in an "all" search. | |
void | GetMinMaxX (const int &iY, const int &iGrLen) |
For distance-height searches, gets the min and max X grid cells for a given Y grid cell. | |
void | Setup () |
Does final data validation and gets things ready for the NextTree() methods. | |
Protected Attributes | |
clTreePopulation * | mp_oTreePop |
Pointer to tree population. | |
clPlot * | mp_oPlot |
Pointer to plot object. | |
clTree *(clTreeSearch::* | function )() |
Function pointer for the appropriate "FindNext..." function. | |
clTree * | mp_oCurrentTree |
The tree that the search is currently on. | |
bool | m_bDistanceHeightUsed |
Whether or not this is a distance and height search. | |
bool | m_bTypeUsed |
Whether or not this is searching by tree type. | |
bool | m_bSpeciesUsed |
Whether or not this is searching by species. | |
bool | m_bAllUsed |
Whether or not this should simply return all - trumps everything else. | |
int | m_iCurrentXGrid |
Current X grid number in an "all" search. | |
int | m_iCurrentYGrid |
Current Y grid number in an "all" search. | |
float | m_fFromX |
X coordinate of search point in a distance/height search. | |
float | m_fFromY |
Y coordinate of search point in a distance/height search. | |
float | m_fDistanceCutoff |
Target maximum distance, in meters, in a distance/height seach. | |
float | m_fHeightCutoff |
Target minimum height, in meters, in a distance/height search - can be zero. | |
short int | m_iMaxX |
Maximum X grid cell number to search in a distance/height search. | |
short int | m_iMaxY |
Maximum Y grid cell number to search in a distance/height search. | |
short int | m_iMinX |
Minimum X grid cell number to search in a distance/height search. | |
short int | m_iMinY |
Minimum Y grid cell number to search in a distance/height search. | |
short int | m_iHomeX |
X grid cell of target point in a distance/height search. | |
short int | m_iHomeY |
Y grid cell of target point in a distance/height search. | |
short int | m_iWhatTypes |
Which types to search for in a search involving type. | |
short int | m_iStartHeightDiv |
Starting height division to search in tree hash table in a type search. | |
short int | m_iEndHeightDiv |
Ending height division to search in tree hash table in a type search. | |
bool | m_bSeeds |
Whether seeds are being searched for in a type search. | |
bool | m_bSeedlings |
Whether seedlings are being searched for in a type search. | |
bool | m_bSaplings |
Whether saplings are being searched for in a type search. | |
bool | m_bAdults |
Whether adults are being searched for in a type search. | |
bool | m_bSnags |
Whether snags are being searched for in a type search. | |
bool | m_bWoody_Debris |
Whether woody debris is being searched for in a type search. | |
bool * | mp_bWhatSpecies |
Which species to search for in a search involving species. | |
Friends | |
class | clTreePopulation |
class | clTestTreePopulation |
For testing purposes. |
For each request for a population to return a set of trees, a treeSearch object will be created. It will keep the required search attributes and control the tree flow.
When a clTreeSearch object is returned as a result of a query to a clTreePopulation object, use NextTree() (including for the first tree) to return trees until NextTree() returns NULL, indicating the end of the list.
A clTreeSearch object acts like a simultaneous placeholder and filter in the hash table. It keeps its place and, when NextTree() is called, sifts through until it finds the next tree meeting the appropriate criteria.
The clTreeSearch class and the clTreePopulation class are friends of each other. This lets them access each other's methods and data, which is importantvbecause the tree searching code lives in the clTreeSearch object but accesses trees in the clTreePopulation object.
Requirements for a successful search:
Copyright 2003 Charles D. Canham.
clTreeSearch::clTreeSearch | ( | clTreePopulation * | p_oTreePop, | |
clPlot * | p_oPlot | |||
) |
Constructor.
The constructor initializes variables and sets up the tree results linked list.
In setting up the linked list, it makes the initial dummy record and sets mp_currentTree to that record. This makes sure that even if no trees are returned or there are errors thrown during searching, NextTree correctly returns NULL to the object that originally requested the search.
p_oTreePop | Pointer to the tree population object | |
p_oPlot | Pointer to the plot object |
clTreeSearch::~clTreeSearch | ( | ) |
Destructor.
Frees memory.
clTree* clTreeSearch::NextTree | ( | ) | [inline] |
Returns the next tree matching this search's criteria.
NextTree just calls the appropriate FindNext... function.
void clTreeSearch::StartOver | ( | ) |
Starts the tree search over.
After this is called, the next call to NextTree() will return the first tree, and the whole list can be traversed again. (This does NOT trigger a new search.)
clTree* clTreeSearch::FindNextDHTree | ( | ) | [protected] |
Optimized for finding trees where only distance and height are specified.
clTree* clTreeSearch::FindNextTSTree | ( | ) | [protected] |
Optimized for finding trees where only type and species are specified.
clTree* clTreeSearch::FindNextTTree | ( | ) | [protected] |
Optimized for finding trees where only type is specified.
clTree* clTreeSearch::FindNextAllTree | ( | ) | [protected] |
Sets up the object to find all trees.
Finds the first one and sets mp_gridList to hold the grid cell the search is traversing so it can traverse on the fly when requested.
clTree* clTreeSearch::FindFirstDHTree | ( | ) | [protected] |
Finds the first tree in a distance/height search.
Then sets up the current tree pointer and the current grid numbers.
clTree* clTreeSearch::FindFirstTSTree | ( | ) | [protected] |
Finds the first tree in a type/species search.
Then sets up the current tree pointer and the current grid numbers.
clTree* clTreeSearch::FindFirstTTree | ( | ) | [protected] |
Finds the first tree in a type search.
Then sets up the current tree pointer and the current grid numbers.
clTree* clTreeSearch::FindFirstAllTree | ( | ) | [protected] |
Finds the first tree in an "all" search.
Then sets up the current tree pointer and the current grid numbers.
void clTreeSearch::GetMinMaxX | ( | const int & | iY, | |
const int & | iGrLen | |||
) | [protected] |
For distance-height searches, gets the min and max X grid cells for a given Y grid cell.
We search a circle, and we know XY of center, and Y of point on edge of circle - we can solve for X as X2 = X1 - square root(distance^2 - (Y1 - Y2)^2). The min and max values are set in m_iMinX and m_iMaxX, uncorrected for torus.
iY | The Y grid cell, uncorrected for torus. | |
iGrLen | Grid length |
void clTreeSearch::Setup | ( | ) | [protected] |
Does final data validation and gets things ready for the NextTree() methods.
friend class clTreePopulation [friend] |
friend class clTestTreePopulation [friend] |
For testing purposes.
clTreePopulation* clTreeSearch::mp_oTreePop [protected] |
Pointer to tree population.
clPlot* clTreeSearch::mp_oPlot [protected] |
Pointer to plot object.
clTree*(clTreeSearch::* clTreeSearch::function)() [protected] |
Function pointer for the appropriate "FindNext..." function.
clTree* clTreeSearch::mp_oCurrentTree [protected] |
The tree that the search is currently on.
bool clTreeSearch::m_bDistanceHeightUsed [protected] |
Whether or not this is a distance and height search.
bool clTreeSearch::m_bTypeUsed [protected] |
Whether or not this is searching by tree type.
bool clTreeSearch::m_bSpeciesUsed [protected] |
Whether or not this is searching by species.
bool clTreeSearch::m_bAllUsed [protected] |
Whether or not this should simply return all - trumps everything else.
int clTreeSearch::m_iCurrentXGrid [protected] |
Current X grid number in an "all" search.
int clTreeSearch::m_iCurrentYGrid [protected] |
Current Y grid number in an "all" search.
float clTreeSearch::m_fFromX [protected] |
X coordinate of search point in a distance/height search.
float clTreeSearch::m_fFromY [protected] |
Y coordinate of search point in a distance/height search.
float clTreeSearch::m_fDistanceCutoff [protected] |
Target maximum distance, in meters, in a distance/height seach.
float clTreeSearch::m_fHeightCutoff [protected] |
Target minimum height, in meters, in a distance/height search - can be zero.
short int clTreeSearch::m_iMaxX [protected] |
Maximum X grid cell number to search in a distance/height search.
short int clTreeSearch::m_iMaxY [protected] |
Maximum Y grid cell number to search in a distance/height search.
short int clTreeSearch::m_iMinX [protected] |
Minimum X grid cell number to search in a distance/height search.
short int clTreeSearch::m_iMinY [protected] |
Minimum Y grid cell number to search in a distance/height search.
short int clTreeSearch::m_iHomeX [protected] |
X grid cell of target point in a distance/height search.
short int clTreeSearch::m_iHomeY [protected] |
Y grid cell of target point in a distance/height search.
short int clTreeSearch::m_iWhatTypes [protected] |
Which types to search for in a search involving type.
The types are indicated by flipped bits in this variable. From right to left the bits are seedling, sapling, adult. More in the header file.
short int clTreeSearch::m_iStartHeightDiv [protected] |
Starting height division to search in tree hash table in a type search.
short int clTreeSearch::m_iEndHeightDiv [protected] |
Ending height division to search in tree hash table in a type search.
bool clTreeSearch::m_bSeeds [protected] |
Whether seeds are being searched for in a type search.
bool clTreeSearch::m_bSeedlings [protected] |
Whether seedlings are being searched for in a type search.
bool clTreeSearch::m_bSaplings [protected] |
Whether saplings are being searched for in a type search.
bool clTreeSearch::m_bAdults [protected] |
Whether adults are being searched for in a type search.
bool clTreeSearch::m_bSnags [protected] |
Whether snags are being searched for in a type search.
bool clTreeSearch::m_bWoody_Debris [protected] |
Whether woody debris is being searched for in a type search.
bool* clTreeSearch::mp_bWhatSpecies [protected] |
Which species to search for in a search involving species.
This array is sized # species.