1f220fa62Smrg/* 2f220fa62Smrg * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) 3f220fa62Smrg * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved. 4f220fa62Smrg * 5f220fa62Smrg * Permission is hereby granted, free of charge, to any person obtaining a 6f220fa62Smrg * copy of this software and associated documentation files (the "Software"), 7f220fa62Smrg * to deal in the Software without restriction, including without limitation 8f220fa62Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 9f220fa62Smrg * and/or sell copies of the Software, and to permit persons to whom the 10f220fa62Smrg * Software is furnished to do so, subject to the following conditions: 11f220fa62Smrg * 12f220fa62Smrg * The above copyright notice including the dates of first publication and 13f220fa62Smrg * either this permission notice or a reference to 14f220fa62Smrg * http://oss.sgi.com/projects/FreeB/ 15f220fa62Smrg * shall be included in all copies or substantial portions of the Software. 16f220fa62Smrg * 17f220fa62Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18f220fa62Smrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19f220fa62Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 20f220fa62Smrg * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21f220fa62Smrg * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF 22f220fa62Smrg * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23f220fa62Smrg * SOFTWARE. 24f220fa62Smrg * 25f220fa62Smrg * Except as contained in this notice, the name of Silicon Graphics, Inc. 26f220fa62Smrg * shall not be used in advertising or otherwise to promote the sale, use or 27f220fa62Smrg * other dealings in this Software without prior written authorization from 28f220fa62Smrg * Silicon Graphics, Inc. 29f220fa62Smrg */ 30f220fa62Smrg/* 31f220fa62Smrg*/ 32f220fa62Smrg 33f220fa62Smrg#ifndef _DIRECTEDLINE_H 34f220fa62Smrg#define _DIRECTEDLINE_H 35f220fa62Smrg 36f220fa62Smrg#include "definitions.h" 37f220fa62Smrg#include "sampledLine.h" 38f220fa62Smrg 39f220fa62Smrgenum {INCREASING, DECREASING}; 40f220fa62Smrg 41f220fa62Smrgclass directedLine { 42f220fa62Smrg short direction; /*INCREASING or DECREASING*/ 43f220fa62Smrg sampledLine* sline; 44f220fa62Smrg directedLine* next; /*double linked list*/ 45f220fa62Smrg directedLine* prev; /*double linked list*/ 46f220fa62Smrg 47f220fa62Smrg /*in case we need a list of polygons each 48f220fa62Smrg *consisting of a double linked list 49f220fa62Smrg */ 50f220fa62Smrg directedLine* nextPolygon; 51f220fa62Smrg 52f220fa62Smrg /*optimization make cutoff polygon faster*/ 53f220fa62Smrg/* directedLine* prevPolygon;*/ 54f220fa62Smrg 55f220fa62Smrg Int rootBit; /*1 if this is a root of the polygon, set by setRootBit*/ 56f220fa62Smrg /*and reset by resetRootBit()*/ 57f220fa62Smrg 58f220fa62Smrg directedLine* rootLink; /*fast root-finding*/ 59f220fa62Smrg 60f220fa62Smrg 61f220fa62Smrg 62f220fa62Smrgpublic: 63f220fa62Smrg directedLine(short dir, sampledLine* sl); 64f220fa62Smrg directedLine(); 65f220fa62Smrg ~directedLine(); 66f220fa62Smrg 67f220fa62Smrg void init(short dir, sampledLine* sl); 68f220fa62Smrg 69f220fa62Smrg Real* head(); /*points[0] if INCREASING, points[n-1] otherwise*/ 70f220fa62Smrg Real* tail(); /*points[n-1] if INCREASING, points[0] otherwise*/ 71f220fa62Smrg Real* getVertex(Int i); /*points[i] if INCREASING, points[n-1-i] otherwise*/ 72f220fa62Smrg Int get_npoints() {return sline->get_npoints();} 73f220fa62Smrg directedLine* getPrev() {return prev;} 74f220fa62Smrg directedLine* getNext() {return next;} 75f220fa62Smrg directedLine* getNextPolygon() {return nextPolygon;} 76f220fa62Smrg sampledLine* getSampledLine() {return sline;} 77f220fa62Smrg 78f220fa62Smrg short getDirection(){return direction;} 79f220fa62Smrg void putDirection(short dir) {direction = dir;} 80f220fa62Smrg void putPrev(directedLine *p) {prev = p;} 81f220fa62Smrg void putNext(directedLine *p) {next = p;} 82f220fa62Smrg 83f220fa62Smrg /*insert a new line between prev and this*/ 84f220fa62Smrg void insert(directedLine* nl); 85f220fa62Smrg 86f220fa62Smrg /*delete all the polygons following the link: nextPolygon. 87f220fa62Smrg *notice that sampledLine is not deleted. The caller is 88f220fa62Smrg *responsible for that 89f220fa62Smrg */ 90f220fa62Smrg void deletePolygonList(); 91f220fa62Smrg void deleteSinglePolygon(); 92f220fa62Smrg 93f220fa62Smrg void deleteSinglePolygonWithSline(); //also delete sanmpled line 94f220fa62Smrg void deletePolygonListWithSline(); //also delete sanmpled line 95f220fa62Smrg 96f220fa62Smrg void deleteSingleLine(directedLine* dline); 97f220fa62Smrg directedLine* deleteDegenerateLines(); 98f220fa62Smrg directedLine* deleteDegenerateLinesAllPolygons(); 99f220fa62Smrg directedLine* cutIntersectionAllPoly(int& cutOccur); 100f220fa62Smrg 101f220fa62Smrg /*check to see if the list forms a closed polygon 102f220fa62Smrg *return 1 if yes 103f220fa62Smrg */ 104f220fa62Smrg short isPolygon(); 105f220fa62Smrg 106f220fa62Smrg Int compInY(directedLine* nl); 107f220fa62Smrg Int compInX(directedLine* nl); 108f220fa62Smrg 109f220fa62Smrg /*return an array of pointers. 110f220fa62Smrg *the 111f220fa62Smrg */ 112f220fa62Smrg directedLine** sortAllPolygons(); 113f220fa62Smrg 114f220fa62Smrg Int numEdges(); 115f220fa62Smrg Int numEdgesAllPolygons(); 116f220fa62Smrg Int numPolygons(); 117f220fa62Smrg 118f220fa62Smrg /*check if the head of this edge is connected to 119f220fa62Smrg *the tail of the prev 120f220fa62Smrg */ 121f220fa62Smrg short isConnected(); 122f220fa62Smrg 123f220fa62Smrg Real polyArea(); 124f220fa62Smrg 125f220fa62Smrg void printSingle(); 126f220fa62Smrg void printList(); 127f220fa62Smrg void printAllPolygons(); 128f220fa62Smrg void writeAllPolygons(char* filename); 129f220fa62Smrg 130f220fa62Smrg 131f220fa62Smrg /*insert a polygon: using nextPolygon*/ 132f220fa62Smrg directedLine* insertPolygon(directedLine* newpolygon); 133f220fa62Smrg directedLine* cutoffPolygon(directedLine *p); 134f220fa62Smrg 135f220fa62Smrg Int toArraySinglePolygon(directedLine** array, Int index); 136f220fa62Smrg directedLine** toArrayAllPolygons(Int& total_num_edges); 137f220fa62Smrg 138f220fa62Smrg void connectDiagonal(directedLine* v1, directedLine* v2, 139f220fa62Smrg directedLine** ret_p1, 140f220fa62Smrg directedLine** ret_p2, 141f220fa62Smrg sampledLine** generatedLine, directedLine* list); 142f220fa62Smrg 143f220fa62Smrg /*generate two slines 144f220fa62Smrg */ 145f220fa62Smrg void connectDiagonal_2slines(directedLine* v1, directedLine* v2, 146f220fa62Smrg directedLine** ret_p1, 147f220fa62Smrg directedLine** ret_p2, 148f220fa62Smrg directedLine* list); 149f220fa62Smrg 150f220fa62Smrg Int samePolygon(directedLine* v1, directedLine* v2); 151f220fa62Smrg void setRootBit() {rootBit = 1;} 152f220fa62Smrg void resetRootBit() {rootBit = 0;} 153f220fa62Smrg directedLine* findRoot(); 154f220fa62Smrg 155f220fa62Smrg void rootLinkSet(directedLine* r) {rootLink = r;} 156f220fa62Smrg directedLine* rootLinkFindRoot(); 157f220fa62Smrg 158f220fa62Smrg //the chain from begin to end is deleted (the space is deallocated) 159f220fa62Smrg //and a new edge(which connectes the head of begin and the tail of end) 160f220fa62Smrg // is inserted. The new polygon is returned. 161f220fa62Smrg //notice that "this" is arbitrary 162f220fa62Smrg directedLine* deleteChain(directedLine* begin, directedLine* end); 163f220fa62Smrg}; 164f220fa62Smrg 165f220fa62SmrgdirectedLine* readAllPolygons(char* filename); 166f220fa62Smrg 167f220fa62Smrgextern Int compV2InY(Real A[2], Real B[2]); 168f220fa62Smrgextern Int compV2InX(Real A[2], Real B[2]); 169f220fa62Smrg 170f220fa62Smrg#endif 171f220fa62Smrg 172