diff --git a/Schrick-Noah_CS-7353_HW4.aux b/Schrick-Noah_CS-7353_HW4.aux new file mode 100644 index 0000000..70b4678 --- /dev/null +++ b/Schrick-Noah_CS-7353_HW4.aux @@ -0,0 +1,6 @@ +\relax +\@writefile{toc}{\contentsline {section}{\numberline {1}Problem Introduction}{1}{}\protected@file@percent } +\@writefile{toc}{\contentsline {section}{\numberline {2}Program Preface}{2}{}\protected@file@percent } +\@writefile{toc}{\contentsline {section}{\numberline {3}Coding Approach}{3}{}\protected@file@percent } +\@writefile{toc}{\contentsline {section}{\numberline {4}Results}{3}{}\protected@file@percent } +\gdef \@abspage@last{3} diff --git a/Schrick-Noah_CS-7353_HW4.log b/Schrick-Noah_CS-7353_HW4.log new file mode 100644 index 0000000..07aedb9 --- /dev/null +++ b/Schrick-Noah_CS-7353_HW4.log @@ -0,0 +1,154 @@ +This is pdfTeX, Version 3.141592653-2.6-1.40.23 (TeX Live 2021/Arch Linux) (preloaded format=pdflatex 2022.2.14) 9 MAR 2022 21:14 +entering extended mode + restricted \write18 enabled. + %&-line parsing enabled. +**Schrick-Noah_CS-7353_HW4 +(./Schrick-Noah_CS-7353_HW4.tex +LaTeX2e <2021-11-15> patch level 1 +L3 programming layer <2021-11-22> +(/usr/share/texmf-dist/tex/latex/base/article.cls +Document Class: article 2021/10/04 v1.4n Standard LaTeX document class +(/usr/share/texmf-dist/tex/latex/base/size10.clo +File: size10.clo 2021/10/04 v1.4n Standard LaTeX file (size option) +) +\c@part=\count183 +\c@section=\count184 +\c@subsection=\count185 +\c@subsubsection=\count186 +\c@paragraph=\count187 +\c@subparagraph=\count188 +\c@figure=\count189 +\c@table=\count190 +\abovecaptionskip=\skip47 +\belowcaptionskip=\skip48 +\bibindent=\dimen138 +) +(/usr/share/texmf-dist/tex/latex/graphics/graphicx.sty +Package: graphicx 2021/09/16 v1.2d Enhanced LaTeX Graphics (DPC,SPQR) + +(/usr/share/texmf-dist/tex/latex/graphics/keyval.sty +Package: keyval 2014/10/28 v1.15 key=value parser (DPC) +\KV@toks@=\toks16 +) +(/usr/share/texmf-dist/tex/latex/graphics/graphics.sty +Package: graphics 2021/03/04 v1.4d Standard LaTeX Graphics (DPC,SPQR) + +(/usr/share/texmf-dist/tex/latex/graphics/trig.sty +Package: trig 2021/08/11 v1.11 sin cos tan (DPC) +) +(/usr/share/texmf-dist/tex/latex/graphics-cfg/graphics.cfg +File: graphics.cfg 2016/06/04 v1.11 sample graphics configuration +) +Package graphics Info: Driver file: pdftex.def on input line 107. + +(/usr/share/texmf-dist/tex/latex/graphics-def/pdftex.def +File: pdftex.def 2020/10/05 v1.2a Graphics/color driver for pdftex +)) +\Gin@req@height=\dimen139 +\Gin@req@width=\dimen140 +) +(/usr/share/texmf-dist/tex/latex/base/inputenc.sty +Package: inputenc 2021/02/14 v1.3d Input encoding file +\inpenc@prehook=\toks17 +\inpenc@posthook=\toks18 +) +(/usr/share/texmf-dist/tex/latex/float/float.sty +Package: float 2001/11/08 v1.3d Float enhancements (AL) +\c@float@type=\count191 +\float@exts=\toks19 +\float@box=\box50 +\@float@everytoks=\toks20 +\@floatcapt=\box51 +) +(/usr/share/texmf-dist/tex/latex/tools/indentfirst.sty +Package: indentfirst 1995/11/23 v1.03 Indent first paragraph (DPC) +) +(/usr/share/texmf-dist/tex/latex/l3backend/l3backend-pdftex.def +File: l3backend-pdftex.def 2021-12-14 L3 backend support: PDF output (pdfTeX) +\l__color_backend_stack_int=\count192 +\l__pdf_internal_box=\box52 +) +(./Schrick-Noah_CS-7353_HW4.aux) +\openout1 = `Schrick-Noah_CS-7353_HW4.aux'. + +LaTeX Font Info: Checking defaults for OML/cmm/m/it on input line 13. +LaTeX Font Info: ... okay on input line 13. +LaTeX Font Info: Checking defaults for OMS/cmsy/m/n on input line 13. +LaTeX Font Info: ... okay on input line 13. +LaTeX Font Info: Checking defaults for OT1/cmr/m/n on input line 13. +LaTeX Font Info: ... okay on input line 13. +LaTeX Font Info: Checking defaults for T1/cmr/m/n on input line 13. +LaTeX Font Info: ... okay on input line 13. +LaTeX Font Info: Checking defaults for TS1/cmr/m/n on input line 13. +LaTeX Font Info: ... okay on input line 13. +LaTeX Font Info: Checking defaults for OMX/cmex/m/n on input line 13. +LaTeX Font Info: ... okay on input line 13. +LaTeX Font Info: Checking defaults for U/cmr/m/n on input line 13. +LaTeX Font Info: ... okay on input line 13. + +(/usr/share/texmf-dist/tex/context/base/mkii/supp-pdf.mkii +[Loading MPS to PDF converter (version 2006.09.02).] +\scratchcounter=\count193 +\scratchdimen=\dimen141 +\scratchbox=\box53 +\nofMPsegments=\count194 +\nofMParguments=\count195 +\everyMPshowfont=\toks21 +\MPscratchCnt=\count196 +\MPscratchDim=\dimen142 +\MPnumerator=\count197 +\makeMPintoPDFobject=\count198 +\everyMPtoPDFconversion=\toks22 +) (/usr/share/texmf-dist/tex/latex/epstopdf-pkg/epstopdf-base.sty +Package: epstopdf-base 2020-01-24 v2.11 Base part for package epstopdf +Package epstopdf-base Info: Redefining graphics rule for `.eps' on input line 4 +85. + +(/usr/share/texmf-dist/tex/latex/latexconfig/epstopdf-sys.cfg +File: epstopdf-sys.cfg 2010/07/13 v1.3 Configuration of (r)epstopdf for TeX Liv +e +)) +LaTeX Font Info: External font `cmex10' loaded for size +(Font) <12> on input line 15. +LaTeX Font Info: External font `cmex10' loaded for size +(Font) <8> on input line 15. +LaTeX Font Info: External font `cmex10' loaded for size +(Font) <6> on input line 15. + +(./Schrick-Noah_CS-7353_HW4.toc) +\tf@toc=\write3 +\openout3 = `Schrick-Noah_CS-7353_HW4.toc'. + +LaTeX Font Info: External font `cmex10' loaded for size +(Font) <7> on input line 25. +LaTeX Font Info: External font `cmex10' loaded for size +(Font) <5> on input line 25. + [1 + +{/var/lib/texmf/fonts/map/pdftex/updmap/pdftex.map}] [2] [3] (./Schrick-Noah_CS +-7353_HW4.aux) ) +Here is how much of TeX's memory you used: + 1414 strings out of 478353 + 23513 string characters out of 5854635 + 326485 words of memory out of 5000000 + 19564 multiletter control sequences out of 15000+600000 + 407713 words of font info for 41 fonts, out of 8000000 for 9000 + 1141 hyphenation exceptions out of 8191 + 55i,6n,62p,225b,193s stack positions out of 5000i,500n,10000p,200000b,80000s +{/usr/share/texmf-dist/fonts/enc/dvips/cm-super/cm-super-ts1.en +c} +Output written on Schrick-Noah_CS-7353_HW4.pdf (3 pages, 117959 bytes). +PDF statistics: + 65 PDF objects out of 1000 (max. 8388607) + 39 compressed objects within 1 object stream + 0 named destinations out of 1000 (max. 500000) + 1 words of extra memory for PDF output out of 10000 (max. 10000000) + diff --git a/Schrick-Noah_CS-7353_HW4.pdf b/Schrick-Noah_CS-7353_HW4.pdf new file mode 100644 index 0000000..8e03457 Binary files /dev/null and b/Schrick-Noah_CS-7353_HW4.pdf differ diff --git a/Schrick-Noah_CS-7353_HW4.tex b/Schrick-Noah_CS-7353_HW4.tex new file mode 100644 index 0000000..610c1eb --- /dev/null +++ b/Schrick-Noah_CS-7353_HW4.tex @@ -0,0 +1,86 @@ +\documentclass{article} +\usepackage{graphicx} +\graphicspath{ {./images/} } +\usepackage[utf8]{inputenc} +\usepackage{float} +\usepackage{indentfirst} +\setlength{\parskip}{\baselineskip}% + +\title{CS 7353: Analysis of Algorithms Homework 4: Visible Lines Problem} +\author{Noah Schrick} +\date{March 8, 2022} + +\begin{document} + +\maketitle +\tableofcontents + +\section{Problem Introduction} +The Hidden Surface Problem is widely used in computer graphics. When displaying images, +not all images should be visible (for example, if one object is in front of another). +To avoid overlapping images from being displayed and causing collisions, computations are +performed to remove all or parts of an object from the field of vision. +This problem is a simplified version focusing on lines in a 2D plane. Rather than handling shifting +perspectives, this problem will be further simplified to +focus on the perspective as looking down from y=$\infty$. + +The problem statement can be defined as follows: + +You are given n nonvertical lines in the plane, labeled $L_{1}$,...,$L_{n}$, +with the ith line specified by the equation y=$a_{i}$x+$b_{i}$. +We will make the assumption that no three of the lines all meet at a single +point. We say line $L_{i}$ is uppermost at a given x-coordinate $x_{0}$ if its y-coordinate +at $x_{0}$ is greater than the y-coordinates of all the other lines at +$x_{0}$: $a_{i}$$x_{0}$+$b_{i}$>$a_{j}$$x_{0}$$b_{j}$ for all +j$\not=$i. + +We say line $L_{i}$ is visible if there is some x-coordinate at which +it is uppermost-intuitively, some portion of it can be seen if you look down from "y=$\infty$". + +Determine which lines are visible and at which restricted domains. + +\section{Program Preface} +This assignment was given with instruction to implement this in C++, or justify why Python +should be used instead. This problem was solved using C++ on a Linux system. +Attached with submission is a zip folder that contains: +\begin{itemize} + \item{A CMakeLists.txt file for compiling} + \item{An "images" folder that contains:} + \begin{enumerate} + \item{Various images included in this report} + \end{enumerate} + \item{A "src" folder that contains:} + \begin{enumerate} + \item{A Line.cpp and Line.h file for the Line class and associated functions} + \item{A HiddenLines.cpp and HiddenLines.h file for the problem instance class and + associated functions} + \item{A GNUPlot .hpp file for plotting} + \item{The main file} + \end{enumerate} + \item{A "data" folder that contains:} + \begin{enumerate} + \item{A CSV file for defining the line functions to use} + \end{enumerate} + \item{A "build" folder that contains:} + \begin{enumerate} + \item{A build.sh script to simplify the build process} + \item{A run.sh script to simplify running the program} + \item{Various CMake files} + \item{The compiled binaries for the program and associated libraries} + \end{enumerate} +\end{itemize} + +This program requires the installation of GNUPlot for plotting purposes, +but modification can be performed to remove the plotting. Removing the plotting +does not alter the solution computation. +In addition, this program promises no guarantee of working on other Operating Systems - +no testing was conducted on any other platform besides the local Linux machine. + + +\section{Coding Approach} +3 + +\section{Results} +4 + +\end{document} \ No newline at end of file diff --git a/Schrick-Noah_CS-7353_HW4.toc b/Schrick-Noah_CS-7353_HW4.toc new file mode 100644 index 0000000..eb1758f --- /dev/null +++ b/Schrick-Noah_CS-7353_HW4.toc @@ -0,0 +1,4 @@ +\contentsline {section}{\numberline {1}Problem Introduction}{1}{}% +\contentsline {section}{\numberline {2}Program Preface}{2}{}% +\contentsline {section}{\numberline {3}Coding Approach}{3}{}% +\contentsline {section}{\numberline {4}Results}{3}{}% diff --git a/build/CMakeFiles/HLlib.dir/src/HiddenLines.cpp.o b/build/CMakeFiles/HLlib.dir/src/HiddenLines.cpp.o index 37c4136..49a37fd 100644 Binary files a/build/CMakeFiles/HLlib.dir/src/HiddenLines.cpp.o and b/build/CMakeFiles/HLlib.dir/src/HiddenLines.cpp.o differ diff --git a/build/CMakeFiles/linelib.dir/src/Line.cpp.o b/build/CMakeFiles/linelib.dir/src/Line.cpp.o index f96f2df..db9888a 100644 Binary files a/build/CMakeFiles/linelib.dir/src/Line.cpp.o and b/build/CMakeFiles/linelib.dir/src/Line.cpp.o differ diff --git a/build/CMakeFiles/main.dir/src/main.cpp.o b/build/CMakeFiles/main.dir/src/main.cpp.o index 85cccfb..246180b 100644 Binary files a/build/CMakeFiles/main.dir/src/main.cpp.o and b/build/CMakeFiles/main.dir/src/main.cpp.o differ diff --git a/build/libHLlib.a b/build/libHLlib.a index 52e6ade..084ea53 100644 Binary files a/build/libHLlib.a and b/build/libHLlib.a differ diff --git a/build/liblinelib.a b/build/liblinelib.a index 4d0b3e1..2e78179 100644 Binary files a/build/liblinelib.a and b/build/liblinelib.a differ diff --git a/build/main b/build/main index 0f450d4..8042758 100755 Binary files a/build/main and b/build/main differ diff --git a/src/HiddenLines.cpp b/src/HiddenLines.cpp index 89f8f3b..d382215 100644 --- a/src/HiddenLines.cpp +++ b/src/HiddenLines.cpp @@ -20,7 +20,23 @@ HL::HL() } //Print the solution and convert the double::max and double::lowest to inf strings -void print_sol(std::vector& lines){ +void HL::print_sol(std::vector& lines){ + HL inst = *this; + + Gnuplot g1("lines"); + g1.set_title("Original Lines"); + g1.set_xrange(-20,20); + g1.set_yrange(-40,40); + + Gnuplot g2("sol"); + g2.set_title("Piecewise Solution"); + g2.set_xrange(-20,20); + g2.set_yrange(-40,40); + + for(Line line : inst.get_lines()){ + g1.plot_slope(line.get_slope(),line.get_ycept(), "Line "+std::to_string(line.get_id())); + } + for(auto itr = lines.begin(); itr != lines.end(); itr++){ Line line = *itr; double start_range = line.get_vis_start(); @@ -37,7 +53,11 @@ void print_sol(std::vector& lines){ continue; std::cout << "Line ID " << line.get_id() << " visible from x=" << start_print << " to x=" << stop_print << std::endl; + + g2.plot_slope(line.get_slope(), line.get_ycept(), "Line "+std::to_string(line.get_id())); } + g2.set_xrange(-20,20); + wait_for_key(); } //Divide and Conquer Strategy using recursive call to divide ls and merge using merge() @@ -111,10 +131,6 @@ std::vector HL::construct_HWprob(){ //Set to hold all our Lines std::set sorted_lines; std::vector lines; - Gnuplot g1("lines"); - g1.set_title("Original Lines"); - g1.set_xrange(-20,20); - g1.set_yrange(-40,40); //Hold our doubles from each line std::vector tmp_data; @@ -169,13 +185,9 @@ std::vector HL::construct_HWprob(){ line.set_vis_end(std::numeric_limits::max()); *it = line; } - - g1.plot_slope(line.get_slope(),line.get_ycept(), "Line "+std::to_string(line.get_id())); } std::cout << "-----------------------------------------------------" << std::endl; - wait_for_key(); - return lines; } diff --git a/src/HiddenLines.h b/src/HiddenLines.h index c6af5a5..ff17d85 100644 --- a/src/HiddenLines.h +++ b/src/HiddenLines.h @@ -12,15 +12,14 @@ class HL std::vector gen_sol(std::vector& ls); std::vector construct_HWprob(); - std::vector get_lines(); + void print_sol(std::vector& lines); private: std::vector lines; }; std::vector merge(std::vector lh, std::vector rh); -void print_sol(std::vector& lines); std::vector remove_invis(std::vector &merged); diff --git a/src/Line.cpp b/src/Line.cpp index b1a035c..590b708 100644 --- a/src/Line.cpp +++ b/src/Line.cpp @@ -2,13 +2,13 @@ #include "Line.h" -int Line::current_id = 0; +int Line::current_id = 1; Line::Line(double x, double y) { set_slope(x); set_ycept(y); - id = 0; + id = 1; //Arbitrarily just say lines are visible starting at and ending at 0. set_vis_start(0); diff --git a/src/main.cpp b/src/main.cpp index 74ce6cb..6dd3efb 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -18,6 +18,6 @@ int main(int argc, char *argv[]) auto sol = inst.gen_sol(lines); std::cout << "Solution is: " << std::endl; - print_sol(sol); + inst.print_sol(sol); } diff --git a/texput.log b/texput.log new file mode 100644 index 0000000..9908def --- /dev/null +++ b/texput.log @@ -0,0 +1,21 @@ +This is pdfTeX, Version 3.141592653-2.6-1.40.23 (TeX Live 2021/Arch Linux) (preloaded format=pdflatex 2022.2.14) 9 MAR 2022 20:36 +entering extended mode + restricted \write18 enabled. + %&-line parsing enabled. +**Schrick-Noah_CS-7353 + +! Emergency stop. +<*> Schrick-Noah_CS-7353 + +End of file on the terminal! + + +Here is how much of TeX's memory you used: + 3 strings out of 478353 + 127 string characters out of 5854635 + 295989 words of memory out of 5000000 + 18233 multiletter control sequences out of 15000+600000 + 403430 words of font info for 27 fonts, out of 8000000 for 9000 + 1141 hyphenation exceptions out of 8191 + 0i,0n,0p,23b,6s stack positions out of 5000i,500n,10000p,200000b,80000s +! ==> Fatal error occurred, no output PDF file produced!