Disabled external gits

This commit is contained in:
2022-04-07 18:46:57 +02:00
parent 88cb3426ad
commit 15e7120d6d
5316 changed files with 4563444 additions and 6 deletions

View File

@@ -0,0 +1,42 @@
# Copyright (c) 2005-2020 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Common Makefile that builds and runs example.
# Just specify your program basename
PROG=game_of_life
ARGS=2:4 -t 5
LIGHT_ARGS=1:2 -t 5
# Trying to find if icl.exe is set
CXX1 = $(TBB_CXX)-
CXX2 = $(CXX1:icl.exe-=icl.exe)
CXX = $(CXX2:-=cl.exe)
# The C++ compiler options
MYCXXFLAGS = /TP /EHsc /W3 /nologo /D _CONSOLE /D _MBCS /D WIN32 /D _CRT_SECURE_NO_DEPRECATE $(CXXFLAGS)
MYLDFLAGS =/INCREMENTAL:NO /NOLOGO /DEBUG /FIXED:NO $(LDFLAGS)
all: release test
release:
$(CXX) ./src/Evolution.cpp ./src/Game_of_life.cpp ./src/Update_state.cpp /MD /O2 /D NDEBUG $(MYCXXFLAGS) /link tbb.lib $(LIBS) $(MYLDFLAGS) /OUT:$(PROG).exe
debug:
$(CXX) ./src/Evolution.cpp ./src/Game_of_life.cpp ./src/Update_state.cpp /MDd /Od /Zi /D _DEBUG $(MYCXXFLAGS) /link tbb_debug.lib $(LIBS) $(MYLDFLAGS) /OUT:$(PROG).exe
clean:
@cmd.exe /C del $(PROG).exe *.obj *.?db *.manifest
test:
$(PROG) $(ARGS)
light_test:
$(PROG) $(LIGHT_ARGS)

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@@ -0,0 +1,63 @@
// Microsoft Visual C++ generated resource script.
//
#include "resource.h"
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// English (U.S.) resources
/////////////////////////////////////////////////////////////////////////////
//
// Icon
//
// Icon placed first or with lowest ID value becomes application icon
LANGUAGE 9, 1
#pragma code_page(1252)
1 ICON "app.ico"
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE
BEGIN
"resource.h\0"
"\0"
END
2 TEXTINCLUDE
BEGIN
"#include ""afxres.h""\r\n"
"\0"
END
3 TEXTINCLUDE
BEGIN
"\0"
END
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED

View File

@@ -0,0 +1,19 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by app.rc

View File

@@ -0,0 +1,392 @@
<!DOCTYPE html>
<html xmlns:mso="urn:schemas-microsoft-com:office:office" xmlns:msdt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882">
<head>
<meta charset="UTF-8">
<style>
::selection {
background: #b7ffb7;
}
::-moz-selection {
background: #b7ffb7;
}
body {
font-family: Arial, Helvetica, sans-serif;
font-size: 16px;
width: 800px;
margin: 0 auto;
}
#banner {
/* Div for banner */
float:left;
margin: 0px;
margin-bottom: 10px;
width: 100%;
background-color: #0071C5;
z-index: 0;
}
#banner .logo {
/* Apply to logo in banner. Add as class to image tag. */
float: left;
margin-right: 20px;
margin-left: 20px;
margin-top: 15px;
padding-bottom: 5px;
}
h1 {
text-align: center;
font-size: 36px;
}
h1.title {
/* Add as class to H1 in banner */
font-family: "Intel Clear", Verdana, Arial, sans-serif;
font-weight:normal;
color: #FFFFFF;
font-size: 170%;
margin-right: 40px;
margin-left: 40px;
padding-right: 20px;
text-indent: 20px;
}
.h3-alike {
display:inline;
font-size: 1.17em;
font-weight: bold;
color: #0071C5;
}
h3 {
font-size: 1.17em;
font-weight: bold;
color: #0071C5;
}
.h4-alike {
display:inline;
font-size: 1.05em;
font-weight: bold;
}
pre {
font-family: "Consolas", Monaco, monospace;
font-size:small;
background: #fafafa;
margin: 0;
padding-left:20px;
}
#footer {
font-size: small;
}
code {
font-family: "Consolas", Monaco, monospace;
}
.code-block
{
padding-left:20px;
}
.changes {
margin: 1em 0;
}
.changes input:active {
position: relative;
top: 1px;
}
.changes input:hover:after {
padding-left: 16px;
font-size: 10px;
content: 'More';
}
.changes input:checked:hover:after {
content: 'Less';
}
.changes input + .show-hide {
display: none;
}
.changes input:checked + .show-hide {
display: block;
}
ul {
margin: 0;
padding: 0.5em 0 0.5em 2.5em;
}
ul li {
margin-bottom: 3px;
}
ul li:last-child {
margin-bottom: 0;
}
.disc {
list-style-type:disc
}
.circ {
list-style-type:circle
}
.single {
padding: 0 0.5em;
}
/* ------------------------------------------------- */
/* Table styles */
table{
margin-bottom:5pt;
border-collapse:collapse;
margin-left:0px;
margin-top:0.3em;
font-size:10pt;
}
tr{
vertical-align:top;
}
th,
th h3{
padding:4px;
text-align:left;
background-color:#0071C5;
font-weight:bold;
margin-top:1px;
margin-bottom:0;
color:#FFFFFF;
font-size:10pt;
vertical-align:middle;
}
th{
border:1px #dddddd solid;
padding-top:2px;
padding-bottom:0px;
padding-right:3px;
padding-left:3px;
}
td{
border:1px #dddddd solid;
vertical-align:top;
font-size:100%;
text-align:left;
margin-bottom:0;
}
td,
td p{
margin-top:0;
margin-left:0;
text-align:left;
font-size:inherit;
line-height:120%;
}
td p{
margin-bottom:0;
padding-top:5px;
padding-bottom:5px;
padding-right:5px;
padding-left:1px;
}
.noborder{
border:0px none;
}
.noborder1stcol{
border:0px none;
padding-left:0pt;
}
td ol{
font-size:inherit;
margin-left:28px;
}
td ul{
font-size:inherit;
margin-left:24px;
}
.DefListTbl{
width:90%;
margin-left:-3pt;
}
.syntaxdiagramtbl{
margin-left:-3pt;
}
.sdtbl{
}
.sdrow{
}
.sdtblp{
border:0px none;
font-size:inherit;
line-height:120%;
margin-bottom:0;
padding-bottom:0px;
padding-top:5px;
padding-left:0px;
padding-right:5px;
vertical-align:top;
}
.idepara, .ide_para{
border:0px none;
font-size:inherit;
line-height:120%;
margin-bottom:0;
padding-bottom:0px;
padding-top:5px;
padding-left:0px;
padding-right:5px;
vertical-align:top;
}
.specs {
border-collapse:collapse;
}
.specs td, .specs th {
font-size: 14px;
}
.specs td {
border: 1px solid black;
}
.specs td td, .specs td th {
border: none;
}
.specs td, .specs td td, .specs td th {
padding: 0 0.2em 0.2em;
text-align: center;
}
.specs td tr:last-child td,
.specs td tr:last-child th {
padding: 0 0.2em;
}
.serial-time {
}
.modified-time {
width: 6.5em;
}
.compiler {
}
.comp-opt {
}
.sys-specs {
width: 18em;
}
.note {
font-size:small;
font-style: italic;
}
</style>
<title>Intel&reg; Threading Building Blocks. Game_of_life sample</title>
</head>
<body>
<div id="banner">
<img class="logo" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEMAAAAsCAYAAAA+aAX8AAAAAXNSR0IArs4c6QAAAARnQU1BAACx
jwv8YQUAAAAJcEhZcwAALiIAAC4iAari3ZIAAAAZdEVYdFNvZnR3YXJlAEFkb2JlIEltYWdlUmVh
ZHlxyWU8AAAIN0lEQVRoQ+WaCaxdUxSGW2ouatZWaVS15nkqkZhSVERQglLEPCam1BCixhqqCKUS
NIiYpxhqHmouIeaY5ylFzA/v1fev8+/j3N5737v3vtf3buNP/uy9/7X2Ovuse4a997m9mgltbW2L
wRHwcHgFfAx+AH+GCb/BT2fNmvUk5ZXwYOrrOsTcCU5CJ74pPBJeA5+Bn8LfOLmagf/f8Af4NrwD
ngg3wdTHh2pOMMB1Gejx8AE4M85mNqD/A7+D78GXkXQFTIMPwUfhdPg6/AxWTRw29b8QruPD9zwY
zPrwHPi2xxmg3QrfgDfD05BGU24EB1HvC3s7REXgtwDsDzeEY+Ak+AJsUfwE2sJdcBN37V4whiU4
+KGUM2JEBtpzUInZEa5g9y4FcYfAo+GLPmwOND2HFrXrnAUHWgnq0vzDB2+Bt0H9coPs1m3gmNvD
ZyITBu234Jp26XoQfCC80sfTAXVv7wOXskuPgnHoSvnTw9P49MDdyOauAQEXhWdC4Vd4ARxmc1OB
cW0Gv3U+lJDvKFa0ufMg4GXwR3gs7J57sRNoaWnR2+znLB2RkKds6jwItvbckIQiGO+eTkSby71t
qh100qtsUCJxmmpSw5i2gWebR1jWm2047T1gf0vyfViJEKi/TtHua7wMdNJs8U/zDzjUpqYA47k4
O704wY+kUZ2P+glQc5ldac9j323sF1cH2EB6h8BxYZdbRDeDOJ16UBJiHDFuMMdYbhjEGA8DxJ4h
jXIemmMpz6ccqbZ1JUlT/3SrHC+9XeB0MjzV9RHqKFAXVg2nBkH/lxxO8aZYbhjEKEuGQH1BuCKc
z1IAN61jAtiut1wZ+ByIkwa6r9t6ZmhSFZw9eL0gxiMw4SLLDYMYFZNRDbhpcpgwzXI5MOqSEvKM
Ue8D+xU4r/Xe+C8HB1ThkhFgNqAXk6FVqyZuA1LcItBXQd+WUvf6YMslwFZvMs7KvMP/SculwKa3
hfYPPsZpfsvS9QD9PRHbcOmUC9J+H2qfoRJ/0MHgFhHIQC8mQ8twxZ0Ji099vSGegn/TP0BdD/Db
Ycn0nna9yZiceQcetFwKDE/4oNtZCtDeXHoC7dWlU1Uyvs7U6sBHJ7FaBAPU82TYJUAzFnCU+1mq
COyfwGLi6k3G05l34BrL/wFxjA/0mKUcaNqBKiJODHclQ3sLCVqZprfEvVCLtThhiskRDFAvXhnv
QPlfi5uW7ytTL14Nr0Bd1pfDXy1Lv93h6koGLstCLR/SuPJ5SQBBD8hPZATbWs6BrdZk7B4dDNpT
Mjkw3bL0YjLOsxygPUWDyExtD1GNV6JAeyTUBlDCKtbrScYxhfjyj1s+B9o+dnifIj94AnpNyaC9
f3QwkNJCTnjOsvRiMi6xrHiaA3ycyYFNbcqBpisl/aoHWaspGdg03uIc43mb/gOilt3CREslQG80
GedmlkC1KyNPBnU9wOPWMp6Aut0S74HfwIQJ7ldTMjBPdBIiGWC0TRkQlseWNmR2tlwC9DmZjEmW
pQ/zOAKqtwdcrnW/DpOBPtp9Ii6F9lhL1yWIo2zUvVhxzYHeLVcG/QfT/iuTA3qwan+zGndVP8p2
k4G8E/wLW4D6PxTlnxgwaDEjaMe6n+USYOvqZKTbUrjQcor3ZSYHRtjULvCrmgwkfY5oRc9B+3Cb
S4FhIhS+gAtZLgH9Y6GWuQU6mwx9IEqYajlA+47CsZ6lGovFBDTNkA9xM4CmpXsAWySDUrPjqZQl
QBsfnSoB41UKAvS9ouJmDfpaDpTQ2WRcXYinCZm+pdyEtDClPgLloP0unABPp3lrpoZ+KkWskSgP
sVZMhlat2t7LQftE2aoCh0sVBOheXclyCYjTp7W19bUsZAQtJuPLTA39gOhg0D7PJtny1xj1tWA+
sUpAG2j7mZaqAh9tzPSVP+XStL+w/qY1XRlfWdOSYXvp7QKnU6Ayqk4jLZcB2zD4gv1iu52qkvG5
NKPsyrCuPs9aDtDeDr4EtS7RRyXNCgfYLPtYfoC33D0Hul6tE6jOfvsMhVqaT8PWG85PXR+WxlOP
pHUIHPNXDsif7NWAT773STdlX6vK4ebi4WRgWybZqFe86tBXUAw4BL+S7UTautTXo9yFcjdKPbsq
PuQTsKdbZ16YLzZrAgdRRvXLCF/Big/R/wXInn5dffdMt8opNs214Bz6cyqNbUDRcZwTIWjDt3m+
XtcBxq3pvL6p6mFftlFUE+i8JPxRCRGoawVbcVepGcF4V4eTGPNPHv+7NjUGAhzmQOl20fyhphlg
T4CxLcQw9WC9Gxb3P4Q37NY4CHJXCuhSW3JnwEXs0qNgSHqVbw210ZP2XwK0A65/6C6NgziaAU5X
wCIUHB4H86227gKH1+JtL3gd1N5sCdACbgZo5rtgnQKx+hLs/ixsdjBXBd2TtyKNhUOp1/dprgMQ
rx9x16fcn1KbttrIyf9OkICWw1KApvY2YyXbpSBobKf7OGXApFtI+5d3Qq1BDoL6V87GcDVc9Ivq
E4D+bjTQbc1i9demreDu8Ch0ffG6hdnmDMrvFbsSsAXczIGk3fwb4VYe+pwBB9Angkd83ADtqgkq
AjetdTTV1icDlfl+Qi3AP4elHEjaDXscHgFjPdNt4ID6S9B9sNLiKoelmuFuJbCpDJi+hvqz2qFw
iIfWc2AQusxPgvq484vH2eUgtpYHH0Hteeqb75ZwMQ+j+cDg9PlwFDwd6o9sr0KtbWI/tSPgp32M
76H+s6mNX3030df5neGq1OtbZDUbOIlFoFaha0L9j0qfCHeAerDqVtODU8+hNThZfR1fHHbpG6kx
9Or1LzUmVVz+HJXDAAAAAElFTkSuQmCC">
<h1 class="title">Intel&reg; Threading Building Blocks.<br>Game_of_life sample</h1>
</div>
<p>
The "Game of life" example demonstrates interoperability of Intel&#174; Threading Building Blocks (Intel&#174; TBB)
and Microsoft* .NET*.
<br><br>
This program runs 2 simultaneous instances of the classic Conway's "Game of Life".
One of these instances uses serial calculations to update the board. The other one calculates in parallel with Intel TBB.
The visualization is written in managed C++ and uses .NET CLR.
</p>
<div class="changes">
<div class="h3-alike">System Requirements</div>
<input type="checkbox">
<div class="show-hide">
<p>
For the most up to date system requirements, see the <a href="http://software.intel.com/en-us/articles/intel-threading-building-blocks-release-notes">release notes.</a>
</p>
</div>
</div>
<div class="changes">
<div class="h3-alike">Files</div>
<input type="checkbox" checked="checked">
<div class="show-hide">
<dl>
<dt><a href="src/Form1.h">Form1.h</a>, <a href="src/Board.h">Board.h</a>
<dd>Header files for GUI classes.
<dt><a href="src/Evolution.h">Evolution.h</a>, <a href="src/Evolution.cpp">Evolution.cpp</a>
<dd>Contain class hierarchy to implement game evolution in serial and parallel.
<dt><a href="src/Update_state.cpp">Update_state.cpp </a>
<dd>Implements 2 approaches for calculating steps in the program: with the use of SSE intrinsics, and ordinary C++ code.
<dt><a href="src/Game_of_life.cpp">Game_of_life.cpp </a>
<dd>Contains program entry point and other source not related to logical structure of the example.
<dt><a href="Makefile">Makefile</a>
<dd>Makefile for building the example.
</dl>
</div>
</div>
<div class="changes">
<div class="h3-alike">Directories</div>
<input type="checkbox" checked="checked">
<div class="show-hide">
<dl>
<dt><a href="src/">src</a>
<dd>Contains source files mentioned above.
<dt><a href="msvs/">msvs</a>
<dd>Contains Microsoft* Visual Studio* workspace for building and running the example (Windows* systems only).
<dt><a href="xcode/">xcode</a>
<dd>Contains Xcode* IDE workspace for building and running the example (macOS* systems only).
</dl>
<p>For information about the minimum supported version of IDE, see <a href="http://software.intel.com/en-us/articles/intel-threading-building-blocks-release-notes">release notes.</a></p>
</div>
</div>
<div class="changes">
<div class="h3-alike">Build instructions</div>
<input type="checkbox" checked="checked">
<div class="show-hide">
<p>General build directions can be found <a href="../../index.html">here</a>.</p>
</div>
</div>
<br>
<a href="../index.html">Up to parent directory</a>
<hr>
<div class="changes">
<div class="h3-alike">Legal Information</div>
<input type="checkbox">
<div class="show-hide">
<p>
Intel and the Intel logo are trademarks of Intel Corporation in the U.S. and/or other countries.
<br>* Other names and brands may be claimed as the property of others.
<br>&copy; 2020, Intel Corporation
</p>
</div>
</div>
</body>
</html>

View File

@@ -0,0 +1,54 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
using namespace System;
using namespace System::Reflection;
using namespace System::Runtime::CompilerServices;
using namespace System::Runtime::InteropServices;
using namespace System::Security::Permissions;
//
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
//
[assembly:AssemblyTitleAttribute("Automata")];
[assembly:AssemblyDescriptionAttribute("")];
[assembly:AssemblyConfigurationAttribute("")];
[assembly:AssemblyCompanyAttribute("")];
[assembly:AssemblyProductAttribute("Automata")];
[assembly:AssemblyCopyrightAttribute("Copyright (c) 2007")];
[assembly:AssemblyTrademarkAttribute("")];
[assembly:AssemblyCultureAttribute("")];
//
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the value or you can default the Revision and Build Numbers
// by using the '*' as shown below:
[assembly:AssemblyVersionAttribute("1.0.*")];
[assembly:ComVisible(false)];
[assembly:CLSCompliantAttribute(true)];
[assembly:SecurityPermission(SecurityAction::RequestMinimum, UnmanagedCode = true)];

View File

@@ -0,0 +1,103 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#ifndef __BOARD_H__
#define __BOARD_H__
#define WIN32_LEAN_AND_MEAN
#ifndef _CONSOLE
#include <windows.h>
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
#define LabelPtr Label^
#define BoardPtr Board^
#else
#define LabelPtr int*
#define BoardPtr Board*
#endif
struct Matrix
{
int width;
int height;
char* data;
};
#ifndef _CONSOLE
public ref class Board : public System::Windows::Forms::UserControl
#else
class Board
#endif
{
public:
Board(int width, int height, int squareSize, LabelPtr counter);
virtual ~Board();
void seed(int s);
void seed(const BoardPtr s);
#ifndef _CONSOLE
protected:
virtual void OnPaint(PaintEventArgs^ e) override;
void Board::draw(Graphics^ g);
private:
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
void InitializeComponent(void)
{
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
}
#pragma endregion
private: delegate void drawDelegate(Int32);
public:
//! Called from the Evolution thread
void draw( Int32 nCurIteration )
{
if (this->InvokeRequired)
{
drawDelegate^ d = gcnew drawDelegate(this, &Board::draw);
IAsyncResult^ result = BeginInvoke(d, nCurIteration);
EndInvoke(result);
return;
}
m_counter->Text = nCurIteration.ToString();
Invalidate();
}
#endif
public:
Matrix *m_matrix;
private:
#ifndef _CONSOLE
SolidBrush^ m_occupiedBrush;
SolidBrush^ m_freeBrush;
Graphics^ m_graphics;
Graphics^ m_mem_dc;
Bitmap^ m_bmp;
#endif
int m_width;
int m_height;
int m_squareSize;
LabelPtr m_counter;
};
#endif

View File

@@ -0,0 +1,242 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
Evolution.cpp: implementation file for evolution classes; evolution
classes do looped evolution of patterns in a defined
2 dimensional space
*/
#include "Evolution.h"
#include "Board.h"
#include "../../../common/utility/get_default_num_threads.h"
#ifdef USE_SSE
#define GRAIN_SIZE 14
#else
#define GRAIN_SIZE 4000
#endif
#define TIME_SLICE 330
/*
Evolution
*/
/**
Evolution::UpdateMatrix() - moves the calculated destination data
to the source data block. No destination zeroing is required since it will
be completely overwritten during the next calculation cycle.
**/
void Evolution::UpdateMatrix()
{
memcpy(m_matrix->data, m_dest, m_size);
}
/*
SequentialEvolution
*/
//! SequentialEvolution::Run - begins looped evolution
#ifndef _CONSOLE
void SequentialEvolution::Run()
{
#else
void SequentialEvolution::Run(double execution_time, int nthread)
{
printf("Starting game (Sequential evolution)\n");
#endif
m_nIteration = 0;
m_serial_time = 0;
tbb::tick_count t0 = tbb::tick_count::now();
while (!m_done)
{
if( !is_paused )
{
tbb::tick_count t = tbb::tick_count::now();
Step();
tbb::tick_count t1 = tbb::tick_count::now();
++m_nIteration;
double work_time = (t1-t0).seconds();
#ifndef _CONSOLE
if ( work_time * 1000 < TIME_SLICE )
continue;
m_serial_time += work_time;
m_board->draw(m_nIteration);
#else
m_serial_time += work_time;
#endif
}
//! Let the parallel algorithm work uncontended almost the same time
//! as the serial one. See ParallelEvolution::Run() as well.
#ifndef _CONSOLE
m_evt_start_parallel->Set();
m_evt_start_serial->WaitOne();
t0 = tbb::tick_count::now();
#else
t0 = tbb::tick_count::now();
if(m_serial_time > execution_time)
{
printf("iterations count = %d time = %g\n", m_nIteration, m_serial_time);
break;
}
#endif
}
}
//! SequentialEvolution::Step() - override of step method
void SequentialEvolution::Step()
{
if( !is_paused )
{
#ifdef USE_SSE
UpdateState(m_matrix, m_matrix->data, 0, m_matrix->height);
#else
UpdateState(m_matrix, m_dest, 0, (m_matrix->width * m_matrix->height)-1);
UpdateMatrix();
#endif
}
}
/*
ParallelEvolution
*/
//! SequentialEvolution::Run - begins looped evolution
#ifndef _CONSOLE
void ParallelEvolution::Run()
{
#else
void ParallelEvolution::Run(double execution_time, int nthread)
{
if(nthread == utility::get_default_num_threads())
printf("Starting game (Parallel evolution for automatic number of thread(s))\n");
else
printf("Starting game (Parallel evolution for %d thread(s))\n", nthread);
#endif
m_nIteration = 0;
m_parallel_time = 0;
#ifndef _CONSOLE
//! start task scheduler as necessary
if (m_pGlobControl == NULL)
{
m_pGlobControl = new tbb::global_control(tbb::global_control::max_allowed_parallelism, utility::get_default_num_threads());
}
m_evt_start_parallel->WaitOne();
#else
tbb::global_control* pGlobControl = new tbb::global_control(tbb::global_control::max_allowed_parallelism, nthread);
#endif
double work_time = m_serial_time;
tbb::tick_count t0 = tbb::tick_count::now();
while (!m_done)
{
if( !is_paused )
{
tbb::tick_count t = tbb::tick_count::now();
Step();
tbb::tick_count t1 = tbb::tick_count::now();
++m_nIteration;
double real_work_time = (t1-t0).seconds();
#ifndef _CONSOLE
if ( real_work_time < work_time )
continue;
m_parallel_time += real_work_time;
m_board->draw(m_nIteration);
#else
m_parallel_time += real_work_time;
#endif
}
//! Let the serial algorithm work the same time as the parallel one.
#ifndef _CONSOLE
m_evt_start_serial->Set();
m_evt_start_parallel->WaitOne();
work_time = m_serial_time - m_parallel_time;
t0 = tbb::tick_count::now();
#else
t0 = tbb::tick_count::now();
if(m_parallel_time > execution_time)
{
printf("iterations count = %d time = %g\n", m_nIteration, m_parallel_time);
delete pGlobControl; pGlobControl = NULL;
break;
}
#endif
}
if (pGlobControl)
delete pGlobControl;
}
/**
class tbb_parallel_task
TBB requires a class for parallel loop implementations. The actual
loop "chunks" are performed using the () operator of the class.
The blocked_range contains the range to calculate. Please see the
TBB documentation for more information.
**/
#ifndef _CONSOLE
public class tbb_parallel_task
#else
class tbb_parallel_task
#endif
{
public:
static void set_values (Matrix* source, char* dest)
{
m_source = source;
m_dest = dest;
return;
}
void operator()( const tbb::blocked_range<size_t>& r ) const
{
int begin = (int)r.begin(); //! capture lower range number for this chunk
int end = (int)r.end(); //! capture upper range number for this chunk
UpdateState(m_source, m_dest, begin, end);
}
tbb_parallel_task () {}
private:
static Matrix* m_source;
static char* m_dest;
};
Matrix* tbb_parallel_task::m_source;
char* tbb_parallel_task::m_dest;
//! ParallelEvolution::Step() - override of Step method
void ParallelEvolution::Step()
{
size_t begin = 0; //! beginning cell position
#ifdef USE_SSE
size_t end = m_matrix->height; //! ending cell position
#else
size_t end = m_size-1; //! ending cell position
#endif
//! set matrix pointers
tbb_parallel_task::set_values(m_matrix, m_dest);
//! do calculation loop
parallel_for (tbb::blocked_range<size_t> (begin, end, GRAIN_SIZE), tbb_parallel_task());
UpdateMatrix();
}

View File

@@ -0,0 +1,191 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/**
Evolution.h: Header file for evolution classes; evolution classes do
looped evolution of patterns in a defined 2 dimensional space
**/
#ifndef __EVOLUTION_H__
#define __EVOLUTION_H__
#include "Board.h"
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#define WIN32_LEAN_AND_MEAN
#include "tbb/blocked_range.h"
#include "tbb/parallel_for.h"
#include "tbb/tick_count.h"
#include "tbb/global_control.h"
#ifndef _CONSOLE
#include <windows.h>
using namespace System::Threading;
#else
typedef unsigned int Int32;
#endif
void UpdateState(Matrix * m_matrix, char * dest ,int begin, int end);
/**
class Evolution - base class for SequentialEvolution and ParallelEvolution
**/
#ifndef _CONSOLE
public ref class Evolution abstract
#else
class Evolution
#endif
{
public:
Evolution( Matrix *m, //! beginning matrix including initial pattern
BoardPtr board //! the board to update
) : m_matrix(m), m_board(board),
m_size(m_matrix->height * m_matrix->width), m_done(false)
{
//! allocate memory for second matrix data block
m_dest = new char[m_size];
is_paused = false;
#ifdef _CONSOLE
m_serial_time = 0;
#endif
}
virtual ~Evolution()
{
delete[] m_dest;
}
//! Run() - begins looped evolution
#ifndef _CONSOLE
virtual void Run() = 0;
#else
virtual void Run(double execution_time, int nthread) = 0;
#endif
//! Quit() - tell the thread to terminate
virtual void Quit() { m_done = true; }
//! Step() - performs a single evolutionary generation computation on the game matrix
virtual void Step() = 0;
//! SetPause() - change condition of variable is_paused
virtual void SetPause(bool condition)
{
if ( condition == true )
is_paused = true;
else
is_paused = false;
}
protected:
/**
UpdateMatrix() - moves the previous destination data to the source
data block and zeros out destination.
**/
void UpdateMatrix();
protected:
Matrix* m_matrix; //! Pointer to initial matrix
char* m_dest; //! Pointer to calculation destination data
BoardPtr m_board; //! The game board to update
int m_size; //! size of the matrix data block
volatile bool m_done; //! a flag used to terminate the thread
Int32 m_nIteration; //! current calculation cycle index
volatile bool is_paused; //! is needed to perform next iteration
//! Calculation time of the sequential version (since the start), seconds.
/**
This member is updated by the sequential version and read by parallel,
so no synchronization is necessary.
**/
#ifndef _CONSOLE
static volatile double m_serial_time = 0;
static System::Threading::AutoResetEvent ^m_evt_start_serial = gcnew AutoResetEvent(false),
^m_evt_start_parallel = gcnew AutoResetEvent(false);
#else
double m_serial_time;
#endif
};
/**
class SequentialEvolution - derived from Evolution - calculate life generations serially
**/
#ifndef _CONSOLE
public ref class SequentialEvolution: public Evolution
#else
class SequentialEvolution: public Evolution
#endif
{
public:
SequentialEvolution(Matrix *m, BoardPtr board)
: Evolution(m, board)
{}
#ifndef _CONSOLE
virtual void Run() override;
virtual void Step() override;
#else
virtual void Run(double execution_time, int nthread);
virtual void Step();
#endif
};
/**
class ParallelEvolution - derived from Evolution - calculate life generations
in parallel using Intel(R) TBB
**/
#ifndef _CONSOLE
public ref class ParallelEvolution: public Evolution
#else
class ParallelEvolution: public Evolution
#endif
{
public:
ParallelEvolution(Matrix *m, BoardPtr board)
: Evolution(m, board),
m_parallel_time(0)
{
// instantiate a global_control object and save a pointer to it
m_pGlobControl = NULL;
}
~ParallelEvolution()
{
//! delete global_control object
if (m_pGlobControl != NULL)
delete m_pGlobControl;
}
#ifndef _CONSOLE
virtual void Run() override;
virtual void Step() override;
#else
virtual void Run(double execution_time, int nthread);
virtual void Step();
#endif
private:
tbb::global_control* m_pGlobControl;
double m_parallel_time;
};
#endif

View File

@@ -0,0 +1,302 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#ifndef _CONSOLE
#ifndef __FORM1_H__
#define __FORM1_H__
#include <time.h>
#include "Board.h"
#include "Evolution.h"
#define BOARD_SQUARE_SIZE 2
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
FormBorderStyle = System::Windows::Forms::FormBorderStyle::FixedDialog;
ClientSize = System::Drawing::Size(1206, 600+m_ribbonHeight+menuStrip1->Height);
int boardWidth = (ClientRectangle.Width/2-m_sepWidth/2)/BOARD_SQUARE_SIZE;
int boardHeight = (ClientRectangle.Height-menuStrip1->Height-m_ribbonHeight)/BOARD_SQUARE_SIZE;
m_board1 = gcnew Board(boardWidth, boardHeight, BOARD_SQUARE_SIZE, seqGen);
m_board2 = gcnew Board(boardWidth, boardHeight, BOARD_SQUARE_SIZE, parGen);
Controls->Add(m_board1);
Controls->Add(m_board2);
m_board1->Location = System::Drawing::Point(2, m_ribbonHeight + menuStrip1->Height);
m_board2->Location = System::Drawing::Point(2 + boardWidth*BOARD_SQUARE_SIZE + m_sepWidth/2, m_ribbonHeight + menuStrip1->Height);
m_seq = gcnew SequentialEvolution(m_board1->m_matrix, m_board1);
m_par = gcnew ParallelEvolution(m_board2->m_matrix, m_board2);
m_seqThread = gcnew Thread(gcnew ThreadStart(m_seq, &SequentialEvolution::Run));
m_parThread = gcnew Thread(gcnew ThreadStart(m_par, &ParallelEvolution::Run));
Thread::CurrentThread->Priority = ThreadPriority::AboveNormal;
m_suspend = true;
}
protected:
~Form1()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::MenuStrip^ menuStrip1;
private: System::Windows::Forms::ToolStripMenuItem^ fileToolStripMenuItem;
private: System::Windows::Forms::ToolStripMenuItem^ exitToolStripMenuItem;
private: System::Windows::Forms::ToolStripMenuItem^ gameToolStripMenuItem;
private: System::Windows::Forms::ToolStripMenuItem^ seedToolStripMenuItem;
private: System::Windows::Forms::ToolStripMenuItem^ runToolStripMenuItem;
private: System::Windows::Forms::ToolStripMenuItem^ pauseToolStripMenuItem;
private: Board^ m_board1;
private: Board^ m_board2;
private: System::Windows::Forms::Label^ Sequential;
private: System::Windows::Forms::Label^ label1;
private: static const int m_sepWidth = 5;
private: static const int m_ribbonHeight = 26;
private: SequentialEvolution^ m_seq;
private: ParallelEvolution^ m_par;
private: Thread^ m_seqThread;
private: Thread^ m_parThread;
private: System::Windows::Forms::Label^ seqGen;
private: System::Windows::Forms::Label^ parGen;
private: bool m_suspend;
private:
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
void InitializeComponent(void)
{
this->menuStrip1 = (gcnew System::Windows::Forms::MenuStrip());
this->fileToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->exitToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->gameToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->seedToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->runToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->pauseToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->Sequential = (gcnew System::Windows::Forms::Label());
this->label1 = (gcnew System::Windows::Forms::Label());
this->seqGen = (gcnew System::Windows::Forms::Label());
this->parGen = (gcnew System::Windows::Forms::Label());
this->menuStrip1->SuspendLayout();
this->SuspendLayout();
//
// menuStrip1
//
this->menuStrip1->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(2)
{this->fileToolStripMenuItem, this->gameToolStripMenuItem});
this->menuStrip1->Location = System::Drawing::Point(0, 0);
this->menuStrip1->Name = L"menuStrip1";
this->menuStrip1->Padding = System::Windows::Forms::Padding(8, 2, 0, 2);
this->menuStrip1->Size = System::Drawing::Size(1600, 26);
this->menuStrip1->TabIndex = 0;
this->menuStrip1->Text = L"menuStrip1";
this->menuStrip1->ItemClicked += gcnew System::Windows::Forms::ToolStripItemClickedEventHandler(this, &Form1::menuStrip1_ItemClicked);
//
// fileToolStripMenuItem
//
this->fileToolStripMenuItem->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(1) {this->exitToolStripMenuItem});
this->fileToolStripMenuItem->Name = L"fileToolStripMenuItem";
this->fileToolStripMenuItem->Size = System::Drawing::Size(40, 22);
this->fileToolStripMenuItem->Text = L"File";
//
// exitToolStripMenuItem
//
this->exitToolStripMenuItem->Name = L"exitToolStripMenuItem";
this->exitToolStripMenuItem->Size = System::Drawing::Size(99, 22);
this->exitToolStripMenuItem->Text = L"Exit";
this->exitToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::OnExit);
//
// gameToolStripMenuItem
//
this->gameToolStripMenuItem->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(3) {this->seedToolStripMenuItem,
this->runToolStripMenuItem, this->pauseToolStripMenuItem});
this->gameToolStripMenuItem->Name = L"gameToolStripMenuItem";
this->gameToolStripMenuItem->Size = System::Drawing::Size(59, 22);
this->gameToolStripMenuItem->Text = L"Game";
//
// seedToolStripMenuItem
//
this->seedToolStripMenuItem->Name = L"seedToolStripMenuItem";
this->seedToolStripMenuItem->Size = System::Drawing::Size(115, 22);
this->seedToolStripMenuItem->Text = L"Seed";
this->seedToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::OnSeed);
//
// runToolStripMenuItem
//
this->runToolStripMenuItem->Enabled = false;
this->runToolStripMenuItem->Name = L"runToolStripMenuItem";
this->runToolStripMenuItem->Size = System::Drawing::Size(115, 22);
this->runToolStripMenuItem->Text = L"Run";
this->runToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::OnRun);
//
// pauseToolStripMenuItem
//
this->pauseToolStripMenuItem->Enabled = false;
this->pauseToolStripMenuItem->Name = L"pauseToolStripMenuItem";
this->pauseToolStripMenuItem->Size = System::Drawing::Size(115, 22);
this->pauseToolStripMenuItem->Text = L"Pause";
this->pauseToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::OnPauseResume);
//
// Sequential
//
this->Sequential->AutoSize = true;
this->Sequential->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 9, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
static_cast<System::Byte>(0)));
this->Sequential->Location = System::Drawing::Point(12, 32);
this->Sequential->Margin = System::Windows::Forms::Padding(4, 0, 4, 0);
this->Sequential->Name = L"Sequential";
this->Sequential->Size = System::Drawing::Size(239, 18);
this->Sequential->TabIndex = 1;
this->Sequential->Text = L"Sequential Algorithm generation:";
//
// label1
//
this->label1->AutoSize = true;
this->label1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 9, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
static_cast<System::Byte>(0)));
this->label1->Location = System::Drawing::Point(813, 32);
this->label1->Margin = System::Windows::Forms::Padding(4, 0, 4, 0);
this->label1->Name = L"label1";
this->label1->Size = System::Drawing::Size(219, 18);
this->label1->TabIndex = 2;
this->label1->Text = L"Parallel Algorithm generation: ";
//
// seqGen
//
this->seqGen->AutoSize = true;
this->seqGen->Location = System::Drawing::Point(289, 35);
this->seqGen->Margin = System::Windows::Forms::Padding(4, 0, 4, 0);
this->seqGen->Name = L"seqGen";
this->seqGen->Size = System::Drawing::Size(16, 17);
this->seqGen->TabIndex = 3;
this->seqGen->Text = L"0";
//
// parGen
//
this->parGen->AutoSize = true;
this->parGen->Location = System::Drawing::Point(1068, 35);
this->parGen->Margin = System::Windows::Forms::Padding(4, 0, 4, 0);
this->parGen->Name = L"parGen";
this->parGen->Size = System::Drawing::Size(16, 17);
this->parGen->TabIndex = 4;
this->parGen->Text = L"0";
//
// Form1
//
this->AutoScaleDimensions = System::Drawing::SizeF(8, 16);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(1600, 738);
this->Controls->Add(this->parGen);
this->Controls->Add(this->seqGen);
this->Controls->Add(this->label1);
this->Controls->Add(this->Sequential);
this->Controls->Add(this->menuStrip1);
this->MainMenuStrip = this->menuStrip1;
this->Margin = System::Windows::Forms::Padding(4);
this->MaximizeBox = false;
this->Name = L"Form1";
this->Text = L"Game of Life";
this->menuStrip1->ResumeLayout(false);
this->menuStrip1->PerformLayout();
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
protected:
void CloseApp ()
{
m_seq->Quit();
m_par->Quit();
//! Perform a very ungracious exit, should coordinate the threads
System::Environment::Exit(0);
}
protected:
virtual void OnPaint(PaintEventArgs^ e) override
{
}
virtual void OnFormClosing(FormClosingEventArgs^ e) override
{
CloseApp();
}
void OnExit(System::Object^ sender, System::EventArgs^ e)
{
CloseApp();
}
void OnSeed(System::Object^ sender, System::EventArgs^ e)
{
this->seedToolStripMenuItem->Enabled = false;
this->runToolStripMenuItem->Enabled = true;
time_t now = time(NULL);
this->m_board1->seed((int)now);
this->m_board2->seed(this->m_board1);
this->Invalidate();
}
void OnRun(System::Object^ sender, System::EventArgs^ e)
{
this->runToolStripMenuItem->Enabled = false;
this->pauseToolStripMenuItem->Enabled = true;
m_seqThread->Start();
m_parThread->Start();
}
void OnPauseResume(System::Object^ sender, System::EventArgs^ e)
{
if (m_suspend)
{
m_seq->SetPause(true);
m_par->SetPause(true);
this->pauseToolStripMenuItem->Text = L"Resume";
}
else
{
m_seq->SetPause(false);
m_par->SetPause(false);
this->pauseToolStripMenuItem->Text = L"Pause";
}
m_suspend = !m_suspend;
}
private:
System::Void menuStrip1_ItemClicked(System::Object^ sender, System::Windows::Forms::ToolStripItemClickedEventArgs^ e)
{}
};
#endif
#endif

View File

@@ -0,0 +1,227 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
Game_of_life.cpp :
main project file.
*/
#include "Board.h"
#include "Form1.h"
#include "../../../common/utility/get_default_num_threads.h"
#define WIN32_LEAN_AND_MEAN
#ifndef _CONSOLE
#include <windows.h>
#else
#include <iostream>
#include <sstream>
#include <time.h>
#include "Evolution.h"
#define BOARD_SQUARE_SIZE 2
int low; //! lower range limit of threads
int high; //! high range limit of threads
double execution_time; //! time for game of life iterations
#endif
Board::Board(int width, int height, int squareSize, LabelPtr counter)
: m_width(width), m_height(height), m_squareSize(squareSize), m_counter(counter)
{
#ifndef _CONSOLE
InitializeComponent();
DoubleBuffered = true;
this->Width = m_squareSize*width;
this->Height = m_squareSize*height;
#endif
m_matrix = new Matrix();
m_matrix->width = width;
m_matrix->height = height;
m_matrix->data = new char[width*height];
memset(m_matrix->data, 0, width*height);
#ifndef _CONSOLE
m_occupiedBrush = gcnew SolidBrush(Color::Black);
m_freeBrush = gcnew SolidBrush(Color::LightGray);
m_graphics = CreateGraphics();
m_bmp = gcnew Bitmap(Width, Height);
m_mem_dc = Graphics::FromImage(m_bmp);
#endif
}
Board::~Board()
{
#ifndef _CONSOLE
if (components)
{
delete components;
}
#endif
delete[] m_matrix->data;
delete m_matrix;
}
void Board::seed(int s)
{
srand(s);
for (int j=0; j<m_height; j++)
{
for (int i=0; i<m_width; i++)
{
int x = rand()/(int)(((unsigned)RAND_MAX + 1) / 100);
m_matrix->data[i+j*m_width] = x>75? 1: 0; // 25% occupied
}
}
#ifndef _CONSOLE
Invalidate();
#endif
}
void Board::seed( const BoardPtr src )
{
memcpy(m_matrix->data, src->m_matrix->data, m_height*m_width);
#ifndef _CONSOLE
Invalidate();
#endif
}
#ifndef _CONSOLE
void Board::draw(Graphics^ g)
{
m_mem_dc->FillRectangle(m_freeBrush, Drawing::Rectangle(0, 0, m_width*m_squareSize, m_height*m_squareSize));
for (int j=0; j<m_height; j++)
{
for (int i=0; i<m_width; i++)
{
if ( m_matrix->data[i+j*m_width] )
{
m_mem_dc->FillRectangle(m_occupiedBrush, Drawing::Rectangle(i*m_squareSize, j*m_squareSize, m_squareSize, m_squareSize));
}
}
}
g->DrawImage(m_bmp, 0, 0);
}
void Board::OnPaint(PaintEventArgs^ e)
{
draw(e->Graphics);
}
[STAThreadAttribute]
int main(array<System::String ^> ^args)
{
// Enabling Windows XP visual effects before any controls are created
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);
// Create the main window and run it
Application::Run(gcnew Form1());
return 0;
}
#else
//! Print usage of this program
void PrintUsage()
{
printf("Usage: gol [M[:N] -t execution_time]\nM and N are a range of numbers of threads to be used.\nexecution_time is a time (in sec) for execution game_of_life iterations\n");
printf("Default values:\nM:\t\tautomatic\nN:\t\tM\nexecution_time:\t10\n");
}
//! Parse command line
bool ParseCommandLine(int argc, char * argv [])
{
char* s = argv[1];
char* end;
//! command line without parameters
if(argc == 1)
{
low = utility::get_default_num_threads();
high = low;
execution_time = 5;
return true;
}
//! command line with parameters
if(argc != 4)
{
PrintUsage();
return false;
}
if(std::string("-t") != argv[argc-2])
//! process M[:N] parameter
high = strtol(s,&end,0);
low = strtol(s,&end,0);
switch( *end )
{
case ':':
high = strtol(end+1,0,0);
break;
case '\0':
break;
default:
PrintUsage();
return false;
}
if (high < low)
{
std::cout << "Set correct range. Current range: " << low << ":" << high << std::endl;
PrintUsage();
return false;
}
//! process execution_time parameter
execution_time = strtol(argv[argc-1],&end,0);
return true;
}
int main( int argc, char* argv[] )
{
if(!ParseCommandLine( argc, argv ))
return 1;
SequentialEvolution* m_seq;
ParallelEvolution* m_par;
Board* m_board1;
Board* m_board2;
int* count = NULL;
int boardWidth = 300;
int boardHeight = 300;
m_board1 = new Board(boardWidth, boardHeight, BOARD_SQUARE_SIZE, count);
m_board2 = new Board(boardWidth, boardHeight, BOARD_SQUARE_SIZE, count);
time_t now = time(NULL);
printf("Generate Game of life board\n");
m_board1->seed((int)now);
m_board2->seed(m_board1);
m_seq = new SequentialEvolution(m_board1->m_matrix, m_board1);
m_seq->Run(execution_time, 1);
delete m_seq;
m_par = new ParallelEvolution(m_board2->m_matrix, m_board2);
for( int p = low; p <= high; ++p )
{
m_par->Run(execution_time, p);
}
delete m_par;
delete m_board1;
delete m_board2;
return 0;
}
#endif

View File

@@ -0,0 +1,398 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include "Evolution.h"
#ifdef USE_SSE
/* Update states with SSE */
#include <xmmintrin.h>
#include <emmintrin.h>
inline void create_record( char * src, unsigned * dst, unsigned width)
{
dst[0] |= src[width - 1];
for( unsigned a=0; a<31u; ++a )
dst[0] |= src[a]<<(a+1);
unsigned a;
for( a=31u; a<width; ++a )
dst[(a+1)/32u] |= src[a]<<((a+1)%32u);
dst[(a+1)/32u] |= src[0]<<((a+1)%32u);
}
inline void sum_offset( __m128i * X, __m128i * A, __m128i * B, __m128i * C,
unsigned size_sse_ar, unsigned shift )
{
for(unsigned i=0; i<size_sse_ar; ++i)
{
__m128i tmp = _mm_and_si128(A[i],X[shift + i]);
A[i]=_mm_xor_si128(A[i],X[shift + i]);
C[i]=_mm_or_si128(C[i],_mm_and_si128(B[i],tmp));
B[i]=_mm_xor_si128(B[i],tmp);
}
}
inline void shift_left2D( __m128i * X, unsigned height, unsigned size_sse_row )
{
for( unsigned b=0; b<height; ++b )
{
unsigned ind = b*size_sse_row;
unsigned x0 = X[ind].m128i_u32[0] & 1;
X[ind] =_mm_or_si128( _mm_srli_epi16(X[ind],1),
_mm_slli_epi16( _mm_srli_si128( X[ind], 2), 15) );
unsigned x1 = X[ind + 1].m128i_u32[0] & 1;
X[ind+1] =_mm_or_si128( _mm_srli_epi16( X[ind+1],1),
_mm_slli_epi16( _mm_srli_si128( X[ind+1], 2), 15) );
X[ind].m128i_u32[3] |= x1<<31;
unsigned x2 = X[ind + 2].m128i_u32[0] & 1;
X[ind+2] =_mm_or_si128( _mm_srli_epi16( X[ind+2],1),
_mm_slli_epi16( _mm_srli_si128( X[ind+2], 2), 15) );
X[ind+1].m128i_u32[3] |= x2<<31;
unsigned* dst = (unsigned*)&X[ind];
dst[301/32u] |= x0<<(301%32u);
}
}
inline void shift_right2D( __m128i * X, unsigned height, unsigned size_sse_row )
{
for( unsigned b=0; b<height; ++b )
{
unsigned ind = b*size_sse_row;
unsigned x0 = X[ind].m128i_u32[3]; x0>>=31;
X[ind] =_mm_or_si128( _mm_slli_epi16(X[ind],1),
_mm_srli_epi16( _mm_slli_si128( X[ind], 2), 15) );
unsigned x1 = X[ind + 1].m128i_u32[3]; x1>>=31;
X[ind + 1] =_mm_or_si128( _mm_slli_epi16(X[ind + 1],1),
_mm_srli_epi16( _mm_slli_si128( X[ind + 1], 2), 15) );
X[ind + 1].m128i_u32[0] |= x0;
unsigned* dst = (unsigned*)&X[ind];
unsigned x2 = dst[301/32u] & (1<<(301%32u)); x2>>=(301%32u);
X[ind + 2] =_mm_or_si128( _mm_slli_epi16(X[ind + 2],1),
_mm_srli_epi16( _mm_slli_si128( X[ind + 2], 2), 15) );
X[ind + 2].m128i_u32[0] |= x1;
X[ind].m128i_u32[0] |= x2;
}
}
void UpdateState(Matrix * m_matrix, char * dest ,int begin, int end)
{
//300/128 + 1 =3, 3*300=900
unsigned size_sse_row = m_matrix->width/128 + 1; //3
unsigned size_sse_ar=size_sse_row * (end - begin);
__m128i X[906], A[900], B[900], C[900];
char * mas = m_matrix->data;
for( unsigned i=0; i<size_sse_ar; ++i)
{
A[i].m128i_u32[0]=0;A[i].m128i_u32[1]=0;A[i].m128i_u32[2]=0;A[i].m128i_u32[3]=0;
B[i].m128i_u32[0]=0;B[i].m128i_u32[1]=0;B[i].m128i_u32[2]=0;B[i].m128i_u32[3]=0;
C[i].m128i_u32[0]=0;C[i].m128i_u32[1]=0;C[i].m128i_u32[2]=0;C[i].m128i_u32[3]=0;
}
for( unsigned i=0; i<size_sse_ar+6; ++i)
{
X[i].m128i_u32[0]=0;X[i].m128i_u32[1]=0;X[i].m128i_u32[2]=0;X[i].m128i_u32[3]=0;
}
// create X[] with bounds
unsigned height = end - begin;
unsigned width = m_matrix->width;
for( unsigned b = 0 ; b < height; ++b )
{
char* src = &mas[(b + begin)*width];
unsigned* dst = (unsigned*)&X[(b+1)*size_sse_row];
create_record(src, dst, width);
}
// create high row in X[]
char * src;
if(begin == 0)
{
src = &mas[(m_matrix->height-1)*width];
}
else
{
src = &mas[(begin-1)*width];
}
unsigned* dst = (unsigned*)X;
create_record(src, dst, width);
//create lower row in X[]
if(end == m_matrix->height )
{
src = mas;
}
else
{
src = &mas[end*width];
}
dst = (unsigned*)&X[(height+1)*size_sse_row];
create_record(src, dst, width);
//sum( C, B, A, X+offset_for_upwards ); high-left friend
sum_offset(X,A,B,C,size_sse_ar, 0);
//sum( C, B, A, X+offset_for_no_vertical_shift );
sum_offset(X,A,B,C,size_sse_ar, size_sse_row);
//sum( C, B, A, X+offset_for_downwards );
sum_offset(X,A,B,C,size_sse_ar, 2*size_sse_row);
//shift_left( X ); (when view 2D) in our logic it is in right
height = end - begin + 2;
shift_left2D( X, height, size_sse_row);
//sum( C, B, A, X+offset_for_upwards ); high-left friend
sum_offset(X,A,B,C,size_sse_ar, 0);
//sum( C, B, A, X+offset_for_downwards );
sum_offset(X,A,B,C,size_sse_ar, 2*size_sse_row);
//shift_left( X ); (view in 2D) in our logic it is right shift
height = end - begin + 2;
shift_left2D( X, height, size_sse_row);
//sum( C, B, A, X+offset_for_upwards ); high-right friend
sum_offset(X,A,B,C,size_sse_ar, 0);
//sum( C, B, A, X+offset_for_no_vertical_shift ); right friend
sum_offset(X,A,B,C,size_sse_ar, size_sse_row);
//sum( C, B, A, X+offset_for_downwards ); right down friend
sum_offset(X,A,B,C,size_sse_ar, 2*size_sse_row);
//shift_right( X ); (when view in 2D) in our case it left shift.
height = end - begin + 2;
shift_right2D( X, height, size_sse_row);
//X = (X|A)&B&~C (done bitwise over the arrays)
unsigned shift = size_sse_row;
for(unsigned i=0; i<size_sse_ar; ++i)
{
C[i].m128i_u32[0] = ~C[i].m128i_u32[0];
C[i].m128i_u32[1] = ~C[i].m128i_u32[1];
C[i].m128i_u32[2] = ~C[i].m128i_u32[2];
C[i].m128i_u32[3] = ~C[i].m128i_u32[3];
X[shift + i] = _mm_and_si128(_mm_and_si128(_mm_or_si128(X[shift + i],
A[i]),B[i]),C[i]);
}
height = end - begin;
width=m_matrix->width;
for( unsigned b=0; b<height; ++b )
{
char* dst = &dest[(b+begin)*width];
unsigned* src = (unsigned*)&X[(b+1)*size_sse_row];
for( unsigned a=0; a<width; ++a )
{
unsigned c = src[a/32u] & 1<<(a%32u);
dst[a] = c>>(a%32u);
}
}
}
#else
/* end SSE block */
// ----------------------------------------------------------------------
// GetAdjacentCellState() - returns the state (value) of the specified
// adjacent cell of the current cell "cellNumber"
char GetAdjacentCellState(
char* source, // pointer to source data block
int x, // logical width of field
int y, // logical height of field
int cellNumber, // number of cell position to examine
int cp // which adjacent position
)
{
/*
cp
*-- cp=1 ... --- cp=8 (summary: -1-2-3-
-x- -x- -4-x-5-
--- --* -6-7-8- )
*/
char cellState = 0; // return value
// set up boundary flags to trigger field-wrap logic
bool onTopRow = false;
bool onBottomRow = false;
bool onLeftColumn = false;
bool onRightColumn = false;
// check to see if cell is on top row
if (cellNumber < x)
{
onTopRow = true;
}
// check to see if cell is on bottom row
if ((x*y)-cellNumber <= x)
{
onBottomRow = true;
}
// check to see if cell is on left column
if (cellNumber%x == 0)
{
onLeftColumn = true;
}
// check to see if cell is on right column
if ((cellNumber+1)%x == 0)
{
onRightColumn = true;
}
switch (cp)
{
case 1:
if (onTopRow && onLeftColumn)
{
return *(source+((x*y)-1));
}
if (onTopRow && !onLeftColumn)
{
return *(source+(((x*y)-x)+(cellNumber-1)));
}
if (onLeftColumn && !onTopRow)
{
return *(source+(cellNumber-1));
}
return *((source+cellNumber)-(x+1));
case 2:
if (onTopRow)
{
return *(source+(((x*y)-x)+cellNumber));
}
return *((source+cellNumber)-x);
case 3:
if (onTopRow && onRightColumn)
{
return *(source+((x*y)-x));
}
if (onTopRow && !onRightColumn)
{
return *(source+(((x*y)-x)+(cellNumber+1)));
}
if (onRightColumn && !onTopRow)
{
return *(source+((cellNumber-(x*2))+1));
}
return *(source+(cellNumber-(x-1)));
case 4:
if (onRightColumn)
{
return *(source+(cellNumber-(x-1)));
}
return *(source+(cellNumber+1));
case 5:
if (onBottomRow && onRightColumn)
{
return *source;
}
if (onBottomRow && !onRightColumn)
{
return *(source+((cellNumber-((x*y)-x))+1));
}
if (onRightColumn && !onBottomRow)
{
return *(source+(cellNumber+1));
}
return *(source+(((cellNumber+x))+1));
case 6:
if (onBottomRow)
{
return *(source+(cellNumber-((x*y)-x)));
}
return *(source+(cellNumber+x));
case 7:
if (onBottomRow && onLeftColumn)
{
return *(source+(x-1));
}
if (onBottomRow && !onLeftColumn)
{
return *(source+(cellNumber-((x*y)-x)-1));
}
if (onLeftColumn && !onBottomRow)
{
return *(source+(cellNumber+((x*2)-1)));
}
return *(source+(cellNumber+(x-1)));
case 8:
if (onLeftColumn)
{
return *(source+(cellNumber+(x-1)));
}
return *(source+(cellNumber-1));
}
return cellState;
}
char CheckCell(Matrix * m_matrix, int cellNumber)
{
char total = 0;
char* source = m_matrix->data;
//look around to find cell's with status "alive"
for(int i=1; i<9; i++)
{
total += GetAdjacentCellState(source, m_matrix->width, m_matrix->height, cellNumber, i);
}
// if the number of adjacent live cells is < 2 or > 3, the result is a dead
// cell regardless of its current state. (A live cell dies of loneliness if it
// has less than 2 neighbors, and of overcrowding if it has more than 3; a new
// cell is born in an empty spot only if it has exactly 3 neighbors.
if (total < 2 || total > 3)
{
return 0;
}
// if we get here and the cell position holds a living cell, it stays alive
if (*(source+cellNumber))
{
return 1;
}
// we have an empty position. If there are only 2 neighbors, the position stays
// empty.
if (total == 2)
{
return 0;
}
// we have an empty position and exactly 3 neighbors. A cell is born.
return 1;
}
void UpdateState(Matrix * m_matrix, char * dest ,int begin, int end)
{
for (int i=begin; i<=end; i++)
{
*(dest+i) = CheckCell(m_matrix, i);
}
}
#endif
/* end non-SSE block */

View File

@@ -0,0 +1,270 @@
// !$*UTF8*$!
{
archiveVersion = 1;
classes = {
};
objectVersion = 46;
objects = {
/* Begin PBXBuildFile section */
612CD8DD11F573FC00A587B2 /* Game_of_life.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 612CD8DB11F573FC00A587B2 /* Game_of_life.cpp */; };
612CD8DE11F573FC00A587B2 /* Update_state.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 612CD8DC11F573FC00A587B2 /* Update_state.cpp */; };
612CD8E111F5742000A587B2 /* Evolution.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 612CD8E011F5742000A587B2 /* Evolution.cpp */; };
/* End PBXBuildFile section */
/* Begin PBXBuildRule section */
C3C58967218C3E4A00DAC94C /* PBXBuildRule */ = {
isa = PBXBuildRule;
compilerSpec = com.intel.compilers.icc.latest;
fileType = sourcecode.cpp;
isEditable = 1;
outputFiles = (
);
script = "# Type a script or drag a script file from your workspace to insert its path.\n";
};
/* End PBXBuildRule section */
/* Begin PBXCopyFilesBuildPhase section */
8DD76F690486A84900D96B5E /* CopyFiles */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 12;
dstPath = "";
dstSubfolderSpec = 16;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */
612CD8DB11F573FC00A587B2 /* Game_of_life.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Game_of_life.cpp; path = ../src/Game_of_life.cpp; sourceTree = SOURCE_ROOT; };
612CD8DC11F573FC00A587B2 /* Update_state.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Update_state.cpp; path = ../src/Update_state.cpp; sourceTree = SOURCE_ROOT; };
612CD8E011F5742000A587B2 /* Evolution.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Evolution.cpp; path = ../src/Evolution.cpp; sourceTree = SOURCE_ROOT; };
8DD76F6C0486A84900D96B5E /* game_of_life */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = game_of_life; sourceTree = BUILT_PRODUCTS_DIR; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
8DD76F660486A84900D96B5E /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
08FB7794FE84155DC02AAC07 /* game_of_life */ = {
isa = PBXGroup;
children = (
08FB7795FE84155DC02AAC07 /* Source */,
1AB674ADFE9D54B511CA2CBB /* Products */,
);
name = game_of_life;
sourceTree = "<group>";
};
08FB7795FE84155DC02AAC07 /* Source */ = {
isa = PBXGroup;
children = (
612CD8E011F5742000A587B2 /* Evolution.cpp */,
612CD8DB11F573FC00A587B2 /* Game_of_life.cpp */,
612CD8DC11F573FC00A587B2 /* Update_state.cpp */,
);
name = Source;
sourceTree = "<group>";
};
1AB674ADFE9D54B511CA2CBB /* Products */ = {
isa = PBXGroup;
children = (
8DD76F6C0486A84900D96B5E /* game_of_life */,
);
name = Products;
sourceTree = "<group>";
};
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
8DD76F620486A84900D96B5E /* game_of_life */ = {
isa = PBXNativeTarget;
buildConfigurationList = 1DEB923108733DC60010E9CD /* Build configuration list for PBXNativeTarget "game_of_life" */;
buildPhases = (
8DD76F640486A84900D96B5E /* Sources */,
8DD76F660486A84900D96B5E /* Frameworks */,
8DD76F690486A84900D96B5E /* CopyFiles */,
);
buildRules = (
C3C58967218C3E4A00DAC94C /* PBXBuildRule */,
);
dependencies = (
);
name = game_of_life;
productInstallPath = "$(HOME)/bin";
productName = game_of_life;
productReference = 8DD76F6C0486A84900D96B5E /* game_of_life */;
productType = "com.apple.product-type.tool";
};
/* End PBXNativeTarget section */
/* Begin PBXProject section */
08FB7793FE84155DC02AAC07 /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 1000;
};
buildConfigurationList = 1DEB923508733DC60010E9CD /* Build configuration list for PBXProject "game_of_life" */;
compatibilityVersion = "Xcode 3.2";
developmentRegion = English;
hasScannedForEncodings = 1;
knownRegions = (
en,
);
mainGroup = 08FB7794FE84155DC02AAC07 /* game_of_life */;
projectDirPath = "";
projectRoot = "";
targets = (
8DD76F620486A84900D96B5E /* game_of_life */,
);
};
/* End PBXProject section */
/* Begin PBXSourcesBuildPhase section */
8DD76F640486A84900D96B5E /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
612CD8DD11F573FC00A587B2 /* Game_of_life.cpp in Sources */,
612CD8DE11F573FC00A587B2 /* Update_state.cpp in Sources */,
612CD8E111F5742000A587B2 /* Evolution.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXSourcesBuildPhase section */
/* Begin XCBuildConfiguration section */
A1F593C60B8F0E6E00073279 /* Debug64 */ = {
isa = XCBuildConfiguration;
buildSettings = {
COPY_PHASE_STRIP = NO;
GCC_DYNAMIC_NO_PIC = NO;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PREPROCESSOR_DEFINITIONS = _CONSOLE;
GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
HEADER_SEARCH_PATHS = "$(inherited)";
INSTALL_PATH = "$(HOME)/bin";
LD_RUNPATH_SEARCH_PATHS = "$(inherited)";
LIBRARY_SEARCH_PATHS = "$(inherited)";
PRODUCT_NAME = game_of_life;
ZERO_LINK = NO;
};
name = Debug64;
};
A1F593C70B8F0E6E00073279 /* Release64 */ = {
isa = XCBuildConfiguration;
buildSettings = {
GCC_GENERATE_DEBUGGING_SYMBOLS = NO;
GCC_PREPROCESSOR_DEFINITIONS = _CONSOLE;
GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
HEADER_SEARCH_PATHS = "$(inherited)";
INSTALL_PATH = "$(HOME)/bin";
LD_RUNPATH_SEARCH_PATHS = "$(inherited)";
LIBRARY_SEARCH_PATHS = "$(inherited)";
PRODUCT_NAME = game_of_life;
ZERO_LINK = NO;
};
name = Release64;
};
A1F593C80B8F0E6E00073279 /* Debug64 */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ENABLE_TESTABILITY = YES;
GCC_ENABLE_CPP_RTTI = YES;
GCC_MODEL_TUNING = "";
GCC_VERSION = "";
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
HEADER_SEARCH_PATHS = (
"$(TBBROOT)/include",
/opt/intel/tbb/include,
);
ICC_CXX_LANG_DIALECT = "c++11";
LD_RUNPATH_SEARCH_PATHS = "$(TBBROOT)/lib /opt/intel/tbb/lib";
LIBRARY_SEARCH_PATHS = (
"$(TBBROOT)/lib",
/opt/intel/tbb/lib,
);
MACOSX_DEPLOYMENT_TARGET = 10.11;
ONLY_ACTIVE_ARCH = YES;
OTHER_CPLUSPLUSFLAGS = (
"$(OTHER_CFLAGS)",
"-m64",
);
OTHER_LDFLAGS = (
"-m64",
"-ltbb_debug",
);
PRECOMPS_INCLUDE_HEADERS_FROM_BUILT_PRODUCTS_DIR = NO;
SYMROOT = "/tmp/tbb-$(USER)";
VALID_ARCHS = x86_64;
};
name = Debug64;
};
A1F593C90B8F0E6E00073279 /* Release64 */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
GCC_ENABLE_CPP_RTTI = YES;
GCC_MODEL_TUNING = "";
GCC_VERSION = "";
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
HEADER_SEARCH_PATHS = (
"$(TBBROOT)/include",
/opt/intel/tbb/include,
);
ICC_CXX_LANG_DIALECT = "c++11";
LD_RUNPATH_SEARCH_PATHS = "$(TBBROOT)/lib /opt/intel/tbb/lib";
LIBRARY_SEARCH_PATHS = (
"$(TBBROOT)/lib",
/opt/intel/tbb/lib,
);
MACOSX_DEPLOYMENT_TARGET = 10.11;
OTHER_CPLUSPLUSFLAGS = (
"$(OTHER_CFLAGS)",
"-m64",
);
OTHER_LDFLAGS = (
"-m64",
"-ltbb",
);
PRECOMPS_INCLUDE_HEADERS_FROM_BUILT_PRODUCTS_DIR = NO;
SYMROOT = "/tmp/tbb-$(USER)";
VALID_ARCHS = x86_64;
};
name = Release64;
};
/* End XCBuildConfiguration section */
/* Begin XCConfigurationList section */
1DEB923108733DC60010E9CD /* Build configuration list for PBXNativeTarget "game_of_life" */ = {
isa = XCConfigurationList;
buildConfigurations = (
A1F593C60B8F0E6E00073279 /* Debug64 */,
A1F593C70B8F0E6E00073279 /* Release64 */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release64;
};
1DEB923508733DC60010E9CD /* Build configuration list for PBXProject "game_of_life" */ = {
isa = XCConfigurationList;
buildConfigurations = (
A1F593C80B8F0E6E00073279 /* Debug64 */,
A1F593C90B8F0E6E00073279 /* Release64 */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release64;
};
/* End XCConfigurationList section */
};
rootObject = 08FB7793FE84155DC02AAC07 /* Project object */;
}

View File

@@ -0,0 +1,350 @@
<!DOCTYPE html>
<html xmlns:mso="urn:schemas-microsoft-com:office:office" xmlns:msdt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882">
<head>
<meta charset="UTF-8">
<style>
::selection {
background: #b7ffb7;
}
::-moz-selection {
background: #b7ffb7;
}
body {
font-family: Arial, Helvetica, sans-serif;
font-size: 16px;
width: 800px;
margin: 0 auto;
}
#banner {
/* Div for banner */
float:left;
margin: 0px;
margin-bottom: 10px;
width: 100%;
background-color: #0071C5;
z-index: 0;
}
#banner .logo {
/* Apply to logo in banner. Add as class to image tag. */
float: left;
margin-right: 20px;
margin-left: 20px;
margin-top: 15px;
padding-bottom: 5px;
}
h1 {
text-align: center;
font-size: 36px;
}
h1.title {
/* Add as class to H1 in banner */
font-family: "Intel Clear", Verdana, Arial, sans-serif;
font-weight:normal;
color: #FFFFFF;
font-size: 170%;
margin-right: 40px;
margin-left: 40px;
padding-right: 20px;
text-indent: 20px;
}
.h3-alike {
display:inline;
font-size: 1.17em;
font-weight: bold;
color: #0071C5;
}
h3 {
font-size: 1.17em;
font-weight: bold;
color: #0071C5;
}
.h4-alike {
display:inline;
font-size: 1.05em;
font-weight: bold;
}
pre {
font-family: "Consolas", Monaco, monospace;
font-size:small;
background: #fafafa;
margin: 0;
padding-left:20px;
}
#footer {
font-size: small;
}
code {
font-family: "Consolas", Monaco, monospace;
}
.code-block
{
padding-left:20px;
}
.changes {
margin: 1em 0;
}
.changes input:active {
position: relative;
top: 1px;
}
.changes input:hover:after {
padding-left: 16px;
font-size: 10px;
content: 'More';
}
.changes input:checked:hover:after {
content: 'Less';
}
.changes input + .show-hide {
display: none;
}
.changes input:checked + .show-hide {
display: block;
}
ul {
margin: 0;
padding: 0.5em 0 0.5em 2.5em;
}
ul li {
margin-bottom: 3px;
}
ul li:last-child {
margin-bottom: 0;
}
.disc {
list-style-type:disc
}
.circ {
list-style-type:circle
}
.single {
padding: 0 0.5em;
}
/* ------------------------------------------------- */
/* Table styles */
table{
margin-bottom:5pt;
border-collapse:collapse;
margin-left:0px;
margin-top:0.3em;
font-size:10pt;
}
tr{
vertical-align:top;
}
th,
th h3{
padding:4px;
text-align:left;
background-color:#0071C5;
font-weight:bold;
margin-top:1px;
margin-bottom:0;
color:#FFFFFF;
font-size:10pt;
vertical-align:middle;
}
th{
border:1px #dddddd solid;
padding-top:2px;
padding-bottom:0px;
padding-right:3px;
padding-left:3px;
}
td{
border:1px #dddddd solid;
vertical-align:top;
font-size:100%;
text-align:left;
margin-bottom:0;
}
td,
td p{
margin-top:0;
margin-left:0;
text-align:left;
font-size:inherit;
line-height:120%;
}
td p{
margin-bottom:0;
padding-top:5px;
padding-bottom:5px;
padding-right:5px;
padding-left:1px;
}
.noborder{
border:0px none;
}
.noborder1stcol{
border:0px none;
padding-left:0pt;
}
td ol{
font-size:inherit;
margin-left:28px;
}
td ul{
font-size:inherit;
margin-left:24px;
}
.DefListTbl{
width:90%;
margin-left:-3pt;
}
.syntaxdiagramtbl{
margin-left:-3pt;
}
.sdtbl{
}
.sdrow{
}
.sdtblp{
border:0px none;
font-size:inherit;
line-height:120%;
margin-bottom:0;
padding-bottom:0px;
padding-top:5px;
padding-left:0px;
padding-right:5px;
vertical-align:top;
}
.idepara, .ide_para{
border:0px none;
font-size:inherit;
line-height:120%;
margin-bottom:0;
padding-bottom:0px;
padding-top:5px;
padding-left:0px;
padding-right:5px;
vertical-align:top;
}
.specs {
border-collapse:collapse;
}
.specs td, .specs th {
font-size: 14px;
}
.specs td {
border: 1px solid black;
}
.specs td td, .specs td th {
border: none;
}
.specs td, .specs td td, .specs td th {
padding: 0 0.2em 0.2em;
text-align: center;
}
.specs td tr:last-child td,
.specs td tr:last-child th {
padding: 0 0.2em;
}
.serial-time {
}
.modified-time {
width: 6.5em;
}
.compiler {
}
.comp-opt {
}
.sys-specs {
width: 18em;
}
.note {
font-size:small;
font-style: italic;
}
</style>
<title>Intel&reg; Threading Building Blocks. Samples on parallel_for algorithm</title>
</head>
<body>
<div id="banner">
<img class="logo" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEMAAAAsCAYAAAA+aAX8AAAAAXNSR0IArs4c6QAAAARnQU1BAACx
jwv8YQUAAAAJcEhZcwAALiIAAC4iAari3ZIAAAAZdEVYdFNvZnR3YXJlAEFkb2JlIEltYWdlUmVh
ZHlxyWU8AAAIN0lEQVRoQ+WaCaxdUxSGW2ouatZWaVS15nkqkZhSVERQglLEPCam1BCixhqqCKUS
NIiYpxhqHmouIeaY5ylFzA/v1fev8+/j3N5737v3vtf3buNP/uy9/7X2Ovuse4a997m9mgltbW2L
wRHwcHgFfAx+AH+GCb/BT2fNmvUk5ZXwYOrrOsTcCU5CJ74pPBJeA5+Bn8LfOLmagf/f8Af4NrwD
ngg3wdTHh2pOMMB1Gejx8AE4M85mNqD/A7+D78GXkXQFTIMPwUfhdPg6/AxWTRw29b8QruPD9zwY
zPrwHPi2xxmg3QrfgDfD05BGU24EB1HvC3s7REXgtwDsDzeEY+Ak+AJsUfwE2sJdcBN37V4whiU4
+KGUM2JEBtpzUInZEa5g9y4FcYfAo+GLPmwOND2HFrXrnAUHWgnq0vzDB2+Bt0H9coPs1m3gmNvD
ZyITBu234Jp26XoQfCC80sfTAXVv7wOXskuPgnHoSvnTw9P49MDdyOauAQEXhWdC4Vd4ARxmc1OB
cW0Gv3U+lJDvKFa0ufMg4GXwR3gs7J57sRNoaWnR2+znLB2RkKds6jwItvbckIQiGO+eTkSby71t
qh100qtsUCJxmmpSw5i2gWebR1jWm2047T1gf0vyfViJEKi/TtHua7wMdNJs8U/zDzjUpqYA47k4
O704wY+kUZ2P+glQc5ldac9j323sF1cH2EB6h8BxYZdbRDeDOJ16UBJiHDFuMMdYbhjEGA8DxJ4h
jXIemmMpz6ccqbZ1JUlT/3SrHC+9XeB0MjzV9RHqKFAXVg2nBkH/lxxO8aZYbhjEKEuGQH1BuCKc
z1IAN61jAtiut1wZ+ByIkwa6r9t6ZmhSFZw9eL0gxiMw4SLLDYMYFZNRDbhpcpgwzXI5MOqSEvKM
Ue8D+xU4r/Xe+C8HB1ThkhFgNqAXk6FVqyZuA1LcItBXQd+WUvf6YMslwFZvMs7KvMP/SculwKa3
hfYPPsZpfsvS9QD9PRHbcOmUC9J+H2qfoRJ/0MHgFhHIQC8mQ8twxZ0Ji099vSGegn/TP0BdD/Db
Ycn0nna9yZiceQcetFwKDE/4oNtZCtDeXHoC7dWlU1Uyvs7U6sBHJ7FaBAPU82TYJUAzFnCU+1mq
COyfwGLi6k3G05l34BrL/wFxjA/0mKUcaNqBKiJODHclQ3sLCVqZprfEvVCLtThhiskRDFAvXhnv
QPlfi5uW7ytTL14Nr0Bd1pfDXy1Lv93h6koGLstCLR/SuPJ5SQBBD8hPZATbWs6BrdZk7B4dDNpT
Mjkw3bL0YjLOsxygPUWDyExtD1GNV6JAeyTUBlDCKtbrScYxhfjyj1s+B9o+dnifIj94AnpNyaC9
f3QwkNJCTnjOsvRiMi6xrHiaA3ycyYFNbcqBpisl/aoHWaspGdg03uIc43mb/gOilt3CREslQG80
GedmlkC1KyNPBnU9wOPWMp6Aut0S74HfwIQJ7ldTMjBPdBIiGWC0TRkQlseWNmR2tlwC9DmZjEmW
pQ/zOAKqtwdcrnW/DpOBPtp9Ii6F9lhL1yWIo2zUvVhxzYHeLVcG/QfT/iuTA3qwan+zGndVP8p2
k4G8E/wLW4D6PxTlnxgwaDEjaMe6n+USYOvqZKTbUrjQcor3ZSYHRtjULvCrmgwkfY5oRc9B+3Cb
S4FhIhS+gAtZLgH9Y6GWuQU6mwx9IEqYajlA+47CsZ6lGovFBDTNkA9xM4CmpXsAWySDUrPjqZQl
QBsfnSoB41UKAvS9ouJmDfpaDpTQ2WRcXYinCZm+pdyEtDClPgLloP0unABPp3lrpoZ+KkWskSgP
sVZMhlat2t7LQftE2aoCh0sVBOheXclyCYjTp7W19bUsZAQtJuPLTA39gOhg0D7PJtny1xj1tWA+
sUpAG2j7mZaqAh9tzPSVP+XStL+w/qY1XRlfWdOSYXvp7QKnU6Ayqk4jLZcB2zD4gv1iu52qkvG5
NKPsyrCuPs9aDtDeDr4EtS7RRyXNCgfYLPtYfoC33D0Hul6tE6jOfvsMhVqaT8PWG85PXR+WxlOP
pHUIHPNXDsif7NWAT773STdlX6vK4ebi4WRgWybZqFe86tBXUAw4BL+S7UTautTXo9yFcjdKPbsq
PuQTsKdbZ16YLzZrAgdRRvXLCF/Big/R/wXInn5dffdMt8opNs214Bz6cyqNbUDRcZwTIWjDt3m+
XtcBxq3pvL6p6mFftlFUE+i8JPxRCRGoawVbcVepGcF4V4eTGPNPHv+7NjUGAhzmQOl20fyhphlg
T4CxLcQw9WC9Gxb3P4Q37NY4CHJXCuhSW3JnwEXs0qNgSHqVbw210ZP2XwK0A65/6C6NgziaAU5X
wCIUHB4H86227gKH1+JtL3gd1N5sCdACbgZo5rtgnQKx+hLs/ixsdjBXBd2TtyKNhUOp1/dprgMQ
rx9x16fcn1KbttrIyf9OkICWw1KApvY2YyXbpSBobKf7OGXApFtI+5d3Qq1BDoL6V87GcDVc9Ivq
E4D+bjTQbc1i9demreDu8Ch0ffG6hdnmDMrvFbsSsAXczIGk3fwb4VYe+pwBB9Angkd83ADtqgkq
AjetdTTV1icDlfl+Qi3AP4elHEjaDXscHgFjPdNt4ID6S9B9sNLiKoelmuFuJbCpDJi+hvqz2qFw
iIfWc2AQusxPgvq484vH2eUgtpYHH0Hteeqb75ZwMQ+j+cDg9PlwFDwd6o9sr0KtbWI/tSPgp32M
76H+s6mNX3030df5neGq1OtbZDUbOIlFoFaha0L9j0qfCHeAerDqVtODU8+hNThZfR1fHHbpG6kx
9Or1LzUmVVz+HJXDAAAAAElFTkSuQmCC">
<h1 class="title">Intel&reg; Threading Building Blocks.<br>Samples on <code>parallel_for</code> algorithm</h1>
</div>
<p>
This directory has examples of the <code>parallel_for</code> algorithm.
</p>
<div class="changes">
<div class="h3-alike">Directories</div>
<input type="checkbox" checked="checked">
<div class="show-hide">
<dl>
<dt><a href="seismic/readme.html">seismic</a>
<dd>Parallel seismic wave simulation.
<dt><a href="tachyon/readme.html">tachyon</a>
<dd>Parallel 2-D raytracer/renderer.
<dt><a href="polygon_overlay/readme.html">polygon_overlay</a>
<dd>Simple polygon overlay.
<dt><a href="game_of_life/readme.html">game_of_life</a>
<dd>Simple Game of life overlay.
</dl>
</div>
</div>
<br>
<a href="../index.html">Up to parent directory</a>
<hr>
<div class="changes">
<div class="h3-alike">Legal Information:</div>
<input type="checkbox">
<div class="show-hide">
<p>
Intel and the Intel logo are trademarks of Intel Corporation in the U.S. and/or other countries.
<br>* Other names and brands may be claimed as the property of others.
<br>&copy; 2020, Intel Corporation
</p>
</div>
</div>
</body>
</html>

View File

@@ -0,0 +1,56 @@
# Copyright (c) 2005-2020 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Common Makefile that builds and runs example.
# Just specify your program basename
PROG=Pover
ARGS=
LIGHT_ARGS= --polys 10 --size 5x5
# Trying to find if icl.exe is set
CXX1 = $(TBB_CXX)-
CXX2 = $(CXX1:icl.exe-=icl.exe)
CXX = $(CXX2:-=cl.exe)
# The C++ compiler options
# Uncomment one of next lines to choose user interface type (console, gdiplus, direct draw)
#UI = con
UI = gdi
#UI = dd
# Machine architecture, auto-detected from TBB_TARGET_ARCH by default
# Use XARCH variable to change it. See index.html for more information
ARCH0 = $(TBB_TARGET_ARCH)-
ARCH1 = $(ARCH0:ia32-=x86)
ARCH2 = $(ARCH1:intel64-=AMD64)
XARCH = $(ARCH2:-=x86)
MAKEINC = ../../common/gui/Makefile.win
all: release test
release: compiler_check
@$(MAKE) -f $(MAKEINC) UI=$(UI) CXX="$(CXX)" CXXFLAGS="$(CXXFLAGS)" LFLAGS="$(LDFLAGS) tbb.lib tbbmalloc.lib $(LIBS)" XARCH=$(XARCH) RCNAME=pover SOURCE=*.cpp EXE=$(PROG).exe build_one
debug: compiler_check
@$(MAKE) -f $(MAKEINC) UI=$(UI) DEBUG=_debug CXX="$(CXX)" CXXFLAGS="$(CXXFLAGS) /D TBB_USE_DEBUG" LFLAGS="$(LDFLAGS) tbb_debug.lib tbbmalloc_debug.lib $(LIBS)" XARCH=$(XARCH) RCNAME=pover SOURCE=*.cpp EXE=$(PROG).exe build_one
clean:
@cmd.exe /C del $(PROG).exe *.obj *.?db *.manifest msvs\pover.res
test:
$(PROG) $(ARGS)
light_test:
$(PROG) $(LIGHT_ARGS)
compiler_check:
@echo compiler_test>compiler_test && @$(CXX) /E compiler_test >nul 2>&1 || echo "$(CXX) command not found. Check if CXX=$(CXX) is set properly"
@cmd.exe /C del compiler_test

View File

@@ -0,0 +1,61 @@
// Microsoft Visual C++ generated resource script.
//
#include "resource.h"
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "afxres.h"
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// English (U.S.) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
LANGUAGE 9, 1
#pragma code_page(1252)
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE
BEGIN
"resource.h\0"
END
2 TEXTINCLUDE
BEGIN
"#include ""afxres.h""\r\n"
"\0"
END
3 TEXTINCLUDE
BEGIN
"\r\n"
"\0"
END
#endif // APSTUDIO_INVOKED
#endif // English (U.S.) resources
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED

View File

@@ -0,0 +1,30 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by pover.rc
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 101
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1001
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif

View File

@@ -0,0 +1,615 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Polygon overlay
//
// Don't want warnings about deprecated sscanf, getenv
#ifndef _CRT_SECURE_NO_DEPRECATE
#define _CRT_SECURE_NO_DEPRECATE
#endif
#define _MAIN_C_ 1
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cstring>
#include "tbb/tick_count.h"
#include "pover_global.h"
#include "polyover.h"
#include "pover_video.h"
#include "polymain.h"
using namespace std;
#if _DEBUG
const char *faceNames[] = { "North", "East", "South", "West" };
#endif
/**
**/
int main( int argc, char **argv) {
pover_video poly;
poly.threaded = true;
gVideo = &poly;
if(!initializeVideo(argc, argv)) {
return 1;
}
gIsGraphicalVersion = poly.graphic_display();
if(argc > 1) {
if(!ParseCmdLine(argc, argv)) {
if(gIsGraphicalVersion) rt_sleep(10000);
// if graphical, we haven't opened the console window so all the error messages we
// so carefully wrote out disappeared into the ether. :(
exit(1);
}
}
if(gCsvFilename != NULL) {
#define BUFLEN 1000
std::string fname_buf = gCsvFilename;
fname_buf += ".csv";
gCsvFile.open(fname_buf.c_str());
}
// we have gMapXSize and gMapYSize determining the number of "squares"
// we have g_xwinsize and g_ywinsize the total size of the window
// we also have BORDER_SIZE the size of the border between maps
// we need to determine
// g_polyBoxSize -- the number of pixels on each size of each square
if(gIsGraphicalVersion) {
int xpixelsPerMap = (g_xwinsize - 4*BORDER_SIZE) / 3; // three maps, with borders between and outside
gMapXSize = xpixelsPerMap; // make the boxes one per pixel
gPolyXBoxSize = xpixelsPerMap / gMapXSize;
int ypixelsPerMap = (g_ywinsize - 2*BORDER_SIZE); // one map vertically
gMapYSize = ypixelsPerMap; // one pixel per box, rather.
gPolyYBoxSize = ypixelsPerMap / gMapYSize;
if((gPolyXBoxSize == 0) || (gPolyYBoxSize == 0)) {
cout << "The display window is not large enough to show the maps" << std::endl;
int minxSize = 4*BORDER_SIZE + 3*gMapXSize;
int minySize = 2*BORDER_SIZE + gMapYSize;
cout << " Should be at least " << minxSize << " x " << minySize << "." << std::endl;
return 1;
}
map2XLoc = 2*BORDER_SIZE + gMapXSize * gPolyXBoxSize;
maprXLoc = 3*BORDER_SIZE + 2 * gMapXSize * gPolyXBoxSize;
}
else { // not gIsGraphicalVersion
// gMapXSize, gMapYSize, gNPolygons defined in pover_global.h
}
// create two polygon maps
SetRandomSeed(gMyRandomSeed); // for repeatability
gVideo->main_loop();
}
void Usage(int argc, char **argv) {
char *cmdTail = strrchr(*argv, '\\');
if(cmdTail == NULL) {
cmdTail = *argv;
}
else {
cmdTail++;
}
cout << cmdTail << " [threads[:threads2]] [--polys npolys] [--size nnnxnnn] [--seed nnn]" << std::endl;
cout << "Create polygon maps and overlay them." << std::endl << std::endl;
cout << "Parameters:" << std::endl;
cout << " threads[:threads2] - number of threads to run" << std::endl;
cout << " --polys npolys - number of polygons in each map" << std::endl;
cout << " --size nnnxnnn - size of each map (X x Y)" << std::endl;
cout << " --seed nnn - initial value of random number generator" << std::endl;
cout << " --csv filename - write timing data to CSV-format file" << std::endl;
cout << " --grainsize n - set grainsize to n" << std::endl;
cout << " --use_malloc - allocate polygons with malloc instead of scalable allocator" << std::endl;
cout << std::endl;
cout << "npolys must be smaller than the size of the map" << std::endl;
cout << std::endl;
exit(1);
}
bool ParseCmdLine(int argc, char **argv ) {
bool error_found = false;
bool nPolysSpecified = false;
bool nMapSizeSpecified = false;
bool nSeedSpecified = false;
bool csvSpecified = false;
bool grainsizeSpecified = false;
bool mallocSpecified = false;
int origArgc = argc;
char** origArgv = argv;
unsigned int newnPolygons = gNPolygons;
unsigned int newSeed = gMyRandomSeed;
unsigned int newX = gMapXSize;
unsigned int newY = gMapYSize;
unsigned int newGrainSize = gGrainSize;
argc--; argv++;
if(argc > 0 && isdigit((*argv)[0])) {
// first argument is one or two numbers, specifying how mny threads to run
char* end; gThreadsHigh = gThreadsLow = (int)strtol(argv[0],&end,0);
switch( *end) {
case ':': gThreadsHigh = (int)strtol(end+1,0,0); break;
case '\0': break;
default: cout << "Unexpected character in thread specifier: " << *end << std::endl; break;
}
if(gThreadsLow > gThreadsHigh) {
int t = gThreadsLow;
gThreadsLow = gThreadsHigh;
gThreadsHigh = t;
}
argv++; argc--;
}
while(argc > 0) {
// format 1: --size nnnxnnn, where nnn in {0 .. 9}+ -- size of map in "squares"
if(!strncmp("--size", *argv, (size_t)6)) {
if(nMapSizeSpecified) {
cout << " Error: map size multiply specified" << std::endl;
error_found = true;
}
else {
argv++; argc--;
if(argc == 0) {
error_found = true;
cout << " Error: --size must have a value" << std::endl;
}
if(strchr(*argv, 'x') != strrchr(*argv,'x')) {
// more than one 'x'
cout << "Error: map size should be nnnxnnn (" << *argv << ")" << std::endl;
error_found = true;
}
else {
int rval;
rval = sscanf(*argv, "%ux%u", &newX, &newY);
if(rval != 2) {
cout << "Error parsing map size (format should be nnnxnnn (" << *argv << ")" << std::endl;
error_found = true;
}
if(newX == 0 || newY == 0) {
cout << "Error: size of map should be greater than 0 (" << *argv << ")" << std::endl;
error_found = true;
}
}
}
argc--; argv++;
}
// format 2: --seed nnn -- initial random number seed
else if(!strncmp("--seed", *argv, (size_t)6)) {
argv++; argc--;
if(nSeedSpecified) {
cout << "Error: new seed multiply specified" << std::endl;
error_found = true;
}
else {
nSeedSpecified = true;
int rtval = sscanf(*argv, "%u", &newSeed);
if(rtval == 0) {
cout << "Error: --seed should be an unsigned number (instead of " << *argv << ")" << std::endl;
error_found = true;
}
}
argv++; argc--;
}
// format 3: --polys n[n] -- number of polygons in each map
else if(!strncmp("--polys", *argv, (size_t)7)) {
//unsigned int newnPolygons;
argv++; argc--;
if(nPolysSpecified) {
cout << "Error: number of polygons multiply-specified" << std::endl;
error_found = true;
}else {
int rtval = sscanf(*argv, "%u", &newnPolygons);
if(newnPolygons == 0) {
cout << "Error: number of polygons must be greater than 0 (" << *argv << ")" << std::endl;
}
}
argv++; argc--;
}
// format 4: --csv <fileroot> -- name of CSV output file ("xxx" for "xxx.csv")
else if(!strncmp("--csv", *argv, (size_t)5)) {
argv++; argc--;
if(csvSpecified) {
cout << "Error: Multiple specification of CSV file" << std::endl;
error_found = true;
}
else {
gCsvFilename = *argv;
argv++; argc--;
csvSpecified = true;
}
}
else if(!strncmp("--grainsize", *argv, (size_t)11)) {
argv++; argc--;
if(grainsizeSpecified) {
cout << "Error: Multiple specification of grainsize" << std::endl;
error_found = true;
}
else {
int grval = sscanf(*argv, "%u", &newGrainSize);
grainsizeSpecified = true;
if(newGrainSize == 0) {
cout << "Error: grainsize must be greater than 0" << std::endl;
error_found = true;
}
}
argv++; argc--;
}
else if(!strncmp("--use_malloc", *argv, (size_t)12)) {
argv++; argc--;
if(mallocSpecified) {
cout << "Error: --use_malloc multiply-specified" << std::endl;
error_found = true;
}
else {
mallocSpecified = true;
gMBehavior = UseMalloc;
}
}
else {
cout << "Error: unrecognized argument: " << *argv << std::endl;
error_found = true;
argv++; argc--;
}
}
if(!error_found) {
if(newX * newY < newnPolygons) {
error_found = true;
cout << "Error: map size should not be smaller than the number of polygons (gNPolygons = " << newnPolygons << ", map size " << newX << "x" << newY << ")" << std::endl;
}
}
if(!error_found) {
gMapXSize = newX;
gMapYSize = newY;
gNPolygons = newnPolygons;
gMyRandomSeed = newSeed;
gGrainSize = (int)newGrainSize;
}
else {
Usage(origArgc, origArgv);
}
return !error_found;
}
// create a polygon map with at least gNPolygons polygons.
// Usually more than gNPolygons polygons will be generated, because the
// process of growing the polygons results in holes.
bool GenerateMap(Polygon_map_t **newMap, int xSize, int ySize, int gNPolygons, colorcomp_t maxR, colorcomp_t maxG, colorcomp_t maxB) {
bool error_found = false;
int *validPolys;
int *validSide;
int maxSides;
RPolygon *newPoly;
if(xSize <= 0) {
cout << "xSize (" << xSize << ") should be > 0." << std::endl;
error_found = true;
}
if(ySize <= 0) {
cout << "ySize (" << ySize << ") should be > 0." << std::endl;
error_found = true;
}
if(gNPolygons > (xSize * ySize)) {
cout << "gNPolygons (" << gNPolygons << ") should be less than " << (xSize * ySize) << std::endl;
error_found = true;
}
if(error_found) return false;
// the whole map is [xSize x ySize] squares
// the way we create the map is to
// 1) pick nPolygon discrete squares on an [xSize x ySize] grid
// 2) while there are unused squares on the grid
// 3) pick a polygon with a side that has unused squares on a side
// 4) expand the polygon by 1 to occupy the unused squares
//
// Continue until every square on the grid is occupied by a polygon
int *tempMap;
tempMap = (int *)malloc(xSize * ySize * sizeof(int));
for(int i=0;i < xSize; i++) {
for(int j=0;j < ySize; j++) {
tempMap[i*ySize + j] = 0;
}
}
// *newMap = new vector<RPolygon>;
*newMap = new Polygon_map_t;
(*newMap)->reserve(gNPolygons + 1); // how much bigger does this need to be on average?
(*newMap)->push_back(RPolygon(0,0,xSize-1, ySize-1));
for(int i=0; i < gNPolygons; i++) {
int nX;
int nY;
do { // look for an empty square.
nX = NextRan(xSize);
nY = NextRan(ySize);
} while(tempMap[nX * ySize + nY] != 0);
int nR = (maxR * NextRan(1000)) / 999;
int nG = (maxG * NextRan(1000)) / 999;
int nB = (maxB * NextRan(1000)) / 999;
(*newMap)->push_back(RPolygon(nX,nY,nX,nY,nR,nG,nB));
tempMap[nX * ySize + nY] = i+1; // index of this polygon + 1
}
// now have to grow polygons to fill the space.
validPolys = (int *)malloc(4*gNPolygons * sizeof(int));
validSide = (int *)malloc(4*gNPolygons * sizeof(int));
for(int i=0;i<gNPolygons;i++) {
validPolys[4*i] = validPolys[4*i + 1] = validPolys[4*i + 2] = validPolys[4*i + 3] = i + 1;
validSide[4*i] = NORTH_SIDE;
validSide[4*i+1] = EAST_SIDE;
validSide[4*i+2] = SOUTH_SIDE;
validSide[4*i+3] = WEST_SIDE;
}
maxSides = 4*gNPolygons;
while(maxSides > 0) {
int indx = NextRan(maxSides);
int polyIndx = validPolys[indx];
int checkSide = validSide[indx];
int xlow, xhigh, ylow, yhigh;
int xlnew, xhnew, ylnew, yhnew;
(**newMap)[polyIndx].get(&xlow,&ylow,&xhigh,&yhigh);
xlnew = xlow;
xhnew = xhigh;
ylnew = ylow;
yhnew = yhigh;
// can this polygon be expanded along the chosen side?
switch(checkSide) {
case NORTH_SIDE:
// y-1 from xlow to xhigh
ylow = yhigh = (ylow - 1);
ylnew--;
break;
case EAST_SIDE:
// x+1 from ylow to yhigh
xlow = xhigh = (xhigh + 1);
xhnew++;
break;
case SOUTH_SIDE:
// y+1 from xlow to xhigh
ylow = yhigh = (yhigh+1);
yhnew++;
break;
case WEST_SIDE:
// x-1 from ylow to yhigh
xlow = xhigh = (xlow - 1);
xlnew--;
break;
}
bool okay_to_extend = !(((xlow < 0) || (xlow >= xSize)) || ((ylow < 0) || (ylow >= ySize)));
for(int ii = xlow; (ii <= xhigh) && okay_to_extend; ii++) {
for(int jj=ylow; (jj <= yhigh) && okay_to_extend; jj++) {
okay_to_extend = tempMap[ii*ySize + jj] == 0;
}
}
if(okay_to_extend) {
(**newMap)[polyIndx].set(xlnew,ylnew,xhnew,yhnew);
for(int ii = xlow; ii <= xhigh; ii++) {
for(int jj=ylow; jj <= yhigh && okay_to_extend; jj++) {
tempMap[ii*ySize + jj] = polyIndx;
}
}
}
else {
// once we cannot expand along a side, we will never be able to; remove from the list.
for(int i=indx + 1; i < maxSides; i++) {
validPolys[i-1] = validPolys[i];
validSide[i-1] = validSide[i];
}
maxSides--;
}
}
// Once no polygons can be grown, look for unused squares, and fill them with polygons.
for(int j=0;j<ySize;j++) {
for(int i=0;i<xSize;i++) {
if(tempMap[i*ySize+j] == 0) {
// try to grow in the x direction, then the y direction
int ilen = i;
int jlen = j;
while(ilen < (xSize - 1) && tempMap[(ilen+1)*ySize + jlen] == 0) {
ilen++;
}
bool yok = true;
while(yok && jlen < (ySize - 1)) {
for(int ii = i; ii <= ilen && yok; ii++) {
yok = (tempMap[ii*ySize + jlen + 1] == 0);
}
if(yok) {
jlen++;
}
}
// create new polygon and push it on our list.
int nR = (maxR * NextRan(1000)) / 999;
int nG = (maxG * NextRan(1000)) / 999;
int nB = (maxB * NextRan(1000)) / 999;
(*newMap)->push_back(RPolygon(i,j,ilen,jlen,nR,nG,nB));
gNPolygons++;
for(int ii=i; ii<=ilen;ii++) {
for(int jj=j;jj<=jlen;jj++) {
tempMap[ii*ySize + jj] = gNPolygons;
}
}
}
}
}
#if _DEBUG
if(!gIsGraphicalVersion) {
cout << std::endl << "Final Map:" << std::endl;
for(int j=0; j < ySize; j++ ) {
cout << "Row " << setw(2) << j << ":";
for(int i=0;i<xSize;i++) {
int it = tempMap[i*ySize + j];
if(it<10) {
cout << setw(2) << it;
}
else {
char ct = (int)'a' + it - 10;
cout << " " << ct;
}
}
cout << std::endl;
}
}
#endif // _DEBUG
free(tempMap);
free(validPolys);
free(validSide);
return true;
}
void CheckPolygonMap(Polygon_map_t *checkMap) {
#define indx(i,j) (i*gMapYSize + j)
#define rangeCheck(str,n,limit) if(((n)<0)||((n)>=limit)) {cout << "checkMap error: " << str << " out of range (" << n << ")" << std::endl;anError=true;}
#define xRangeCheck(str,n) rangeCheck(str,n,gMapXSize)
#define yRangeCheck(str,n) rangeCheck(str,n,gMapYSize)
// The first polygon is the whole map.
bool anError = false;
int *cArray;
if(checkMap->size() <= 0) {
cout << "checkMap error: no polygons in map" << std::endl;
return;
}
// mapXhigh and mapYhigh are inclusive, that is, if the map is 5x5, those values would be 4.
int mapXhigh, mapYhigh, mapLowX, mapLowY;
int gMapXSize, gMapYSize;
(*checkMap)[0].get(&mapLowX, &mapLowY, &mapXhigh, &mapYhigh);
if((mapLowX !=0) || (mapLowY != 0)) {
cout << "checkMap error: map origin not (0,0) (X=" << mapLowX << ", Y=" << mapLowY << ")" << std::endl;
anError = true;
}
if((mapXhigh < 0) || (mapYhigh < 0)) {
cout << "checkMap error: no area in map (X=" << mapXhigh << ", Y=" << mapYhigh << ")" << std::endl;
anError = true;
}
if(anError) return;
// bounds for array.
gMapXSize = mapXhigh + 1;
gMapYSize = mapYhigh + 1;
cArray = (int *)malloc(sizeof(int)*(gMapXSize*gMapYSize));
for(int i=0; i<gMapXSize; i++) {
for(int j=0; j< gMapYSize; j++) {
cArray[indx(i,j)] = 0;
}
}
int xlow, xhigh, ylow, yhigh;
for(int p=1; p < int(checkMap->size()) && !anError; p++) {
(*checkMap)[p].get(&xlow, &ylow, &xhigh, &yhigh);
xRangeCheck("xlow", xlow);
yRangeCheck("ylow", ylow);
xRangeCheck("xhigh", xhigh);
yRangeCheck("yhigh", yhigh);
if(xlow>xhigh) {
cout << "checkMap error: xlow > xhigh (" << xlow << "," << xhigh << ")" << std::endl;
anError = true;
}
if(ylow>yhigh) {
cout << "checkMap error: ylow > yhigh (" << ylow << "," << yhigh << ")" << std::endl;
anError = true;
}
for(int ii = xlow; ii <= xhigh; ii++) {
for(int jj = ylow; jj <= yhigh; jj++) {
if(cArray[indx(ii,jj)] != 0) {
cout << "checkMap error: polygons " << cArray[indx(ii,jj)] << " and " << p << " intersect" << std::endl;
anError = true;
}
cArray[indx(ii,jj)] = p;
}
}
}
for(int ii=0; ii < gMapXSize; ii++) {
for(int jj=0; jj < gMapYSize; jj++) {
if(cArray[indx(ii,jj)] == 0) {
cout << "checkMap error: block(" << ii << ", " << jj << ") not in any polygon" << std::endl;
anError = true;
}
}
}
free(cArray);
}
bool CompOnePolygon(RPolygon &p1, RPolygon &p2) {
int xl1, xh1, yl1, yh1;
int xl2, xh2, yl2, yh2;
p1.get(&xl1, &yl1, &xh1, &yh1);
p2.get(&xl2, &yl2, &xh2, &yh2);
if(yl1>yl2) return true;
if(yl1<yl2) return false;
return (xl1 > xl2);
}
bool PolygonsEqual(RPolygon *p1, RPolygon *p2) {
int xl1, xh1, yl1, yh1;
int xl2, xh2, yl2, yh2;
p1->get(&xl1, &yl1, &xh1, &yh1);
p2->get(&xl2, &yl2, &xh2, &yh2);
return ((xl1 == xl2) && (yl1==yl2) && (xh1 == xh2) && (yh1 == yh2));
}
bool ComparePolygonMaps(Polygon_map_t *map1, Polygon_map_t *map2) {
// create two new polygon maps, copy the pointers from the original to these.
// we have to skip the first polygon, which is the size of the whole map
Polygon_map_t *t1, *t2;
bool is_ok = true;
t1 = new Polygon_map_t;
t1->reserve(map1->size());
for(unsigned int i=1;i<map1->size(); i++) {
t1->push_back(map1->at(i));
}
t2 = new Polygon_map_t;
t2->reserve(map2->size());
for(unsigned int i=1;i<map2->size();i++) {
t2->push_back(map2->at(i));
}
// sort the two created maps by (xlow, ylow)
sort(t1->begin(), t1->end());
sort(t2->begin(), t2->end());
// compare each element of both maps.
if(t1->size() != t2->size()) {
cout << "Error: maps not the same size ( " << int(t1->size()) << " vs " << int(t2->size()) << ")." << std::endl;
}
int maxSize = (int)((t1->size() < t2->size()) ? t1->size() : t2->size());
for(int i=0; i < maxSize; i++) {
if(!PolygonsEqual(&((*t1)[i]), &((*t2)[i]))) {
cout << "Error: polygons unequal (" << (*t1)[i] << " vs " << (*t2)[i] << std::endl;
is_ok = false;
}
}
delete t1;
delete t2;
return is_ok;
}
void SetRandomSeed(int newSeed) {
srand((unsigned)newSeed);
}
int NextRan(int n) {
// assert(n > 1);
// if we are given 1, we will just return 0
//assert(n < RAND_MAX);
int rrand = rand() << 15 | rand();
if(rrand < 0) rrand = -rrand;
return rrand % n;
}
std::ostream& operator<<(std::ostream& s, const RPolygon &p) {
int xl, yl, xh, yh;
p.get(&xl, &yl, &xh, &yh);
return s << "[(" << xl << "," << yl << ")-(" << xh << "," << yh << ")] ";
}

View File

@@ -0,0 +1,41 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include "pover_global.h" // for declaration of DEFINE and INIT
DEFINE Polygon_map_t *gPolymap1 INIT(0);
DEFINE Polygon_map_t *gPolymap2 INIT(0);
DEFINE Polygon_map_t *gResultMap INIT(0);
extern void Usage(int argc, char **argv);
extern bool ParseCmdLine(int argc, char **argv );
extern bool GenerateMap(Polygon_map_t **newMap, int xSize, int ySize, int gNPolygons, colorcomp_t maxR, colorcomp_t maxG, colorcomp_t maxB);
extern bool PolygonsOverlap(RPolygon *p1, RPolygon *p2, int &xl, int &yl, int &xh, int &yh);
extern void CheckPolygonMap(Polygon_map_t *checkMap);
extern bool CompOnePolygon(RPolygon *p1, RPolygon *p2);
extern bool PolygonsEqual(RPolygon *p1, RPolygon *p2);
extern bool ComparePolygonMaps(Polygon_map_t *map1, Polygon_map_t *map2);
extern void SetRandomSeed(int newSeed);
extern int NextRan(int n);

View File

@@ -0,0 +1,664 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Polygon overlay
//
#include <iostream>
#include <algorithm>
#include <string.h>
#include <cstdlib>
#include <assert.h>
#include "tbb/tick_count.h"
#include "tbb/blocked_range.h"
#include "tbb/parallel_for.h"
#include "tbb/spin_mutex.h"
#include "tbb/global_control.h"
#include "../../common/utility/get_default_num_threads.h"
#include "polyover.h"
#include "polymain.h"
#include "pover_video.h"
using namespace std;
/*!
* @brief intersects a polygon with a map, adding any results to output map
*
* @param[out] resultMap output map (must be allocated)
* @param[in] polygon to be intersected
* @param[in] map intersected against
* @param[in] lock to use when adding output polygons to result map
*
*/
void OverlayOnePolygonWithMap(Polygon_map_t *resultMap, RPolygon *myPoly, Polygon_map_t *map2, tbb::spin_mutex *rMutex) {
int r1, g1, b1, r2, g2, b2;
int myr=0;
int myg=0;
int myb=0;
int p1Area = myPoly->area();
for(unsigned int j=1; (j < map2->size()) && (p1Area > 0); j++) {
RPolygon *p2 = &((*map2)[j]);
RPolygon *pnew;
int newxMin, newxMax, newyMin, newyMax;
myPoly->getColor(&r1, &g1, &b1);
if(PolygonsOverlap(myPoly, p2, newxMin, newyMin, newxMax, newyMax)) {
p2->getColor(&r2, &g2, &b2);
myr = r1 + r2;
myg = g1 + g2;
myb = b1 + b2;
p1Area -= (newxMax-newxMin+1)*(newyMax - newyMin + 1);
if(rMutex) {
tbb::spin_mutex::scoped_lock lock(*rMutex);
resultMap->push_back(RPolygon(newxMin, newyMin, newxMax, newyMax, myr, myg, myb));
}
else {
resultMap->push_back(RPolygon(newxMin, newyMin, newxMax, newyMax, myr, myg, myb));
}
}
}
}
/*!
* @brief Serial version of polygon overlay
* @param[out] output map
* @param[in] first map (map that individual polygons are taken from)
* @param[in] second map (map passed to OverlayOnePolygonWithMap)
*/
void SerialOverlayMaps(Polygon_map_t **resultMap, Polygon_map_t *map1, Polygon_map_t *map2) {
cout << "SerialOverlayMaps called" << std::endl;
*resultMap = new Polygon_map_t;
RPolygon *p0 = &((*map1)[0]);
int mapxSize, mapySize, ignore1, ignore2;
p0->get(&ignore1, &ignore2, &mapxSize, &mapySize);
(*resultMap)->reserve(mapxSize*mapySize); // can't be any bigger than this
// push the map size as the first polygon,
(*resultMap)->push_back(RPolygon(0,0,mapxSize, mapySize));
for(unsigned int i=1; i < map1->size(); i++) {
RPolygon *p1 = &((*map1)[i]);
OverlayOnePolygonWithMap(*resultMap, p1, map2, NULL);
}
}
/*!
* @class ApplyOverlay
* @brief Simple version of parallel overlay (make parallel on polygons in map1)
*/
class ApplyOverlay {
Polygon_map_t *m_map1, *m_map2, *m_resultMap;
tbb::spin_mutex *m_rMutex;
public:
/*!
* @brief functor to apply
* @param[in] r range of polygons to intersect from map1
*/
void operator()( const tbb::blocked_range<int> & r) const {
PRINT_DEBUG("From " << r.begin() << " to " << r.end());
for(int i=r.begin(); i != r.end(); i++) {
RPolygon *myPoly = &((*m_map1)[i]);
OverlayOnePolygonWithMap(m_resultMap, myPoly, m_map2, m_rMutex);
}
}
ApplyOverlay(Polygon_map_t *resultMap, Polygon_map_t *map1, Polygon_map_t *map2, tbb::spin_mutex *rmutex) :
m_resultMap(resultMap), m_map1(map1), m_map2(map2), m_rMutex(rmutex) {}
};
/*!
* @brief apply the parallel algorithm
* @param[out] result_map generated map
* @param[in] polymap1 first map to be applied (algorithm is parallel on this map)
* @param[in] polymap2 second map.
*/
void NaiveParallelOverlay(Polygon_map_t *&result_map, Polygon_map_t &polymap1, Polygon_map_t &polymap2) {
// -----------------------------------
bool automatic_threadcount = false;
if(gThreadsLow == THREADS_UNSET || gThreadsLow == utility::get_default_num_threads()) {
gThreadsLow = gThreadsHigh = utility::get_default_num_threads();
automatic_threadcount = true;
}
result_map = new Polygon_map_t;
RPolygon *p0 = &(polymap1[0]);
int mapxSize, mapySize, ignore1, ignore2;
p0->get(&ignore1, &ignore2, &mapxSize, &mapySize);
result_map->reserve(mapxSize*mapySize); // can't be any bigger than this
// push the map size as the first polygon,
tbb::spin_mutex *resultMutex = new tbb::spin_mutex();
int grain_size = gGrainSize;
for(int nthreads = gThreadsLow; nthreads <= gThreadsHigh; nthreads++) {
tbb::global_control c(tbb::global_control::max_allowed_parallelism, nthreads);
if(gIsGraphicalVersion) {
RPolygon *xp = new RPolygon(0, 0, gMapXSize-1, gMapYSize-1, 0, 0, 0); // Clear the output space
delete xp;
}
// put size polygon in result map
result_map->push_back(RPolygon(0,0,mapxSize, mapySize));
tbb::tick_count t0 = tbb::tick_count::now();
tbb::parallel_for (tbb::blocked_range<int>(1,(int)(polymap1.size()),grain_size), ApplyOverlay(result_map, &polymap1, &polymap2, resultMutex));
tbb::tick_count t1 = tbb::tick_count::now();
double naiveParallelTime = (t1-t0).seconds() * 1000;
cout << "Naive parallel with spin lock and ";
if(automatic_threadcount) cout << "automatic";
else cout << nthreads;
cout << ((nthreads == 1) ? " thread" : " threads");
cout << " took " << naiveParallelTime << " msec : speedup over serial " << (gSerialTime / naiveParallelTime) << std::endl;
if(gCsvFile.is_open()) {
gCsvFile << "," << naiveParallelTime;
}
#if _DEBUG
CheckPolygonMap(result_map);
ComparePolygonMaps(result_map, gResultMap);
#endif
result_map->clear();
}
delete resultMutex;
if(gCsvFile.is_open()) {
gCsvFile << std::endl;
}
// -----------------------------------
}
template<typename T>
void split_at( Flagged_map_t& in_map, Flagged_map_t &left_out, Flagged_map_t &right_out, const T median) {
left_out.reserve(in_map.size());
right_out.reserve(in_map.size());
for(Flagged_map_t::iterator i = in_map.begin(); i != in_map.end(); ++i ) {
RPolygon *p = i->p();
if(p->xmax() < median) {
// in left map
left_out.push_back(*i);
}
else if(p->xmin() >= median) {
right_out.push_back(*i);
// in right map
}
else {
// in both maps.
left_out.push_back(*i);
right_out.push_back(RPolygon_flagged(p, true));
}
}
}
// range that splits the maps as well as the range. the flagged_map_t are
// vectors of pointers, and each range owns its maps (has to free them on destruction.)
template <typename T>
class blocked_range_with_maps {
typedef blocked_range<T> my_range_type;
private:
my_range_type my_range;
Flagged_map_t my_map1;
Flagged_map_t my_map2;
public:
blocked_range_with_maps(
T begin, T end, typename my_range_type::size_type my_grainsize,
Polygon_map_t *p1, Polygon_map_t *p2
)
: my_range(begin, end, my_grainsize)
{
my_map1.reserve(p1->size());
my_map2.reserve(p2->size());
for(int i=1; i < p1->size(); ++i) {
my_map1.push_back(RPolygon_flagged(&((*p1)[i]), false));
}
for(int i=1; i < p2->size(); ++i) {
my_map2.push_back(RPolygon_flagged(&(p2->at(i)), false));
}
}
// copy-constructor required for deep copy of flagged maps. One copy is done at the start of the
// parallel for.
blocked_range_with_maps(const blocked_range_with_maps& other): my_range(other.my_range), my_map1(other.my_map1), my_map2(other.my_map2) { }
bool empty() const { return my_range.empty(); }
bool is_divisible() const { return my_range.is_divisible(); }
#if _DEBUG
void check_my_map() {
assert(my_range.begin() <= my_range.end());
for(Flagged_map_t::iterator ci = my_map1.begin(); ci != my_map1.end(); ++ci) {
RPolygon *rp = ci->p();
assert(rp->xmax() >= my_range.begin());
assert(rp->xmin() < my_range.end());
}
for(Flagged_map_t::iterator ci = my_map2.begin(); ci != my_map2.end(); ++ci) {
RPolygon *rp = ci->p();
assert(rp->xmax() >= my_range.begin());
assert(rp->xmin() < my_range.end());
}
}
void dump_map( Flagged_map_t& mapx) {
cout << " ** MAP **\n";
for( Flagged_map_t::iterator ci = mapx.begin(); ci != mapx.end(); ++ci) {
cout << *(ci->p());
if(ci->isDuplicate()) {
cout << " -- is_duplicate";
}
cout << "\n";
}
cout << "\n";
}
#endif
blocked_range_with_maps(blocked_range_with_maps& lhs_r, split ) : my_range(my_range_type(lhs_r.my_range, split())) {
// lhs_r.my_range makes my_range from [median, high) and rhs_r.my_range from [low, median)
Flagged_map_t original_map1 = lhs_r.my_map1;
Flagged_map_t original_map2 = lhs_r.my_map2;
lhs_r.my_map1.clear();
lhs_r.my_map2.clear();
split_at(original_map1, lhs_r.my_map1, my_map1, my_range.begin());
split_at(original_map2, lhs_r.my_map2, my_map2, my_range.begin());
#if _DEBUG
this->check_my_map();
lhs_r.check_my_map();
#endif
}
const my_range_type& range() const { return my_range; }
Flagged_map_t& map1() { return my_map1; }
Flagged_map_t& map2() { return my_map2; }
};
/*!
* @class ApplySplitOverlay
* @brief parallel by columnar strip
*/
class ApplySplitOverlay {
Polygon_map_t *m_map1, *m_map2, *m_resultMap;
tbb::spin_mutex *m_rMutex;
public:
/*!
* @brief functor for columnar parallel version
* @param[in] r range of map to be operated on
*/
void operator()(/*const*/ blocked_range_with_maps<int> & r) const {
#ifdef _DEBUG
// if we are debugging, serialize the method. That way we can
// see what is happening in each strip without the interleaving
// confusing things.
tbb::spin_mutex::scoped_lock lock(*m_rMutex);
cout << unitbuf << "From " << r.range().begin() << " to " << r.range().end()-1 << std::endl;
#endif
// get yMapSize
int r1, g1, b1, r2, g2, b2;
int myr=-1;
int myg=-1;
int myb=-1;
int i1, i2, i3, yMapSize;
(*m_map1)[0].get(&i1, &i2, &i3, &yMapSize);
Flagged_map_t &fmap1 = r.map1();
Flagged_map_t &fmap2 = r.map2();
// When intersecting polygons from fmap1 and fmap2, if BOTH are flagged
// as duplicate, don't add the result to the output map. We can still
// intersect them, because we are keeping track of how much of the polygon
// is left over from intersecting, and quitting when the polygon is
// used up.
for(unsigned int ii=0; ii < fmap1.size(); ii++) {
RPolygon *p1 = fmap1[ii].p();
bool is_dup = fmap1[ii].isDuplicate();
int parea = p1->area();
p1->getColor(&r1, &g1, &b1);
for(unsigned int jj=0;(jj < fmap2.size()) && (parea > 0); jj++) {
int xl, yl, xh, yh;
RPolygon *p2 = fmap2[jj].p();
if(PolygonsOverlap(p1, p2, xl, yl, xh, yh)) {
if(!(is_dup && fmap2[jj].isDuplicate())) {
p2->getColor(&r2, &g2, &b2);
myr = r1 + r2;
myg = g1 + g2;
myb = b1 + b2;
#ifdef _DEBUG
#else
tbb::spin_mutex::scoped_lock lock(*m_rMutex);
#endif
(*m_resultMap).push_back(RPolygon(xl, yl, xh, yh, myr, myg, myb));
}
parea -= (xh-xl+1)*(yh-yl+1);
}
}
}
}
ApplySplitOverlay(Polygon_map_t *resultMap, Polygon_map_t *map1, Polygon_map_t *map2, tbb::spin_mutex *rmutex) :
m_resultMap(resultMap), m_map1(map1), m_map2(map2), m_rMutex(rmutex) {}
};
/*!
* @brief intersects two maps strip-wise
*
* @param[out] resultMap output map (must be allocated)
* @param[in] polymap1 map to be intersected
* @param[in] polymap2 map to be intersected
*/
void SplitParallelOverlay(Polygon_map_t **result_map, Polygon_map_t *polymap1, Polygon_map_t *polymap2) {
int nthreads;
bool automatic_threadcount = false;
double domainSplitParallelTime;
tbb::tick_count t0, t1;
tbb::spin_mutex *resultMutex;
if(gThreadsLow == THREADS_UNSET || gThreadsLow == utility::get_default_num_threads() ) {
gThreadsLow = gThreadsHigh = utility::get_default_num_threads();
automatic_threadcount = true;
}
*result_map = new Polygon_map_t;
RPolygon *p0 = &((*polymap1)[0]);
int mapxSize, mapySize, ignore1, ignore2;
p0->get(&ignore1, &ignore2, &mapxSize, &mapySize);
(*result_map)->reserve(mapxSize*mapySize); // can't be any bigger than this
resultMutex = new tbb::spin_mutex();
int grain_size;
#ifdef _DEBUG
grain_size = gMapXSize / 4;
#else
grain_size = gGrainSize;
#endif
for(nthreads = gThreadsLow; nthreads <= gThreadsHigh; nthreads++) {
tbb::global_control c(tbb::global_control::max_allowed_parallelism, nthreads);
if(gIsGraphicalVersion) {
RPolygon *xp = new RPolygon(0, 0, gMapXSize-1, gMapYSize-1, 0, 0, 0); // Clear the output space
delete xp;
}
// push the map size as the first polygon,
(*result_map)->push_back(RPolygon(0,0,mapxSize, mapySize));
t0 = tbb::tick_count::now();
tbb::parallel_for (blocked_range_with_maps<int>(0,(int)(mapxSize+1),grain_size, polymap1, polymap2), ApplySplitOverlay((*result_map), polymap1, polymap2, resultMutex));
t1 = tbb::tick_count::now();
domainSplitParallelTime = (t1-t0).seconds()*1000;
cout << "Splitting parallel with spin lock and ";
if(automatic_threadcount) cout << "automatic";
else cout << nthreads;
cout << ((nthreads == 1) ? " thread" : " threads");
cout << " took " << domainSplitParallelTime << " msec : speedup over serial " << (gSerialTime / domainSplitParallelTime) << std::endl;
if(gCsvFile.is_open()) {
gCsvFile << "," << domainSplitParallelTime;
}
#if _DEBUG
CheckPolygonMap(*result_map);
ComparePolygonMaps(*result_map, gResultMap);
#endif
(*result_map)->clear();
}
delete resultMutex;
if(gCsvFile.is_open()) {
gCsvFile << std::endl;
}
}
class ApplySplitOverlayCV {
Polygon_map_t *m_map1, *m_map2;
concurrent_Polygon_map_t *m_resultMap;
public:
/*!
* @brief functor for columnar parallel version
* @param[in] r range of map to be operated on
*/
void operator()(blocked_range_with_maps<int> & r) const {
// get yMapSize
int r1, g1, b1, r2, g2, b2;
int myr=-1;
int myg=-1;
int myb=-1;
int i1, i2, i3, yMapSize;
(*m_map1)[0].get(&i1, &i2, &i3, &yMapSize);
Flagged_map_t &fmap1 = r.map1();
Flagged_map_t &fmap2 = r.map2();
// When intersecting polygons from fmap1 and fmap2, if BOTH are flagged
// as duplicate, don't add the result to the output map. We can still
// intersect them, because we are keeping track of how much of the polygon
// is left over from intersecting, and quitting when the polygon is
// used up.
for(unsigned int ii=0; ii < fmap1.size(); ii++) {
RPolygon *p1 = fmap1[ii].p();
bool is_dup = fmap1[ii].isDuplicate();
int parea = p1->area();
p1->getColor(&r1, &g1, &b1);
for(unsigned int jj=0;(jj < fmap2.size()) && (parea > 0); jj++) {
int xl, yl, xh, yh;
RPolygon *p2 = fmap2[jj].p();
if(PolygonsOverlap(p1, p2, xl, yl, xh, yh)) {
if(!(is_dup && fmap2[jj].isDuplicate())) {
p2->getColor(&r2, &g2, &b2);
myr = r1 + r2;
myg = g1 + g2;
myb = b1 + b2;
(*m_resultMap).push_back(RPolygon(xl, yl, xh, yh, myr, myg, myb));
}
parea -= (xh-xl+1)*(yh-yl+1);
}
}
}
}
ApplySplitOverlayCV(concurrent_Polygon_map_t *resultMap, Polygon_map_t *map1, Polygon_map_t *map2 ) :
m_resultMap(resultMap), m_map1(map1), m_map2(map2) {}
};
/*!
* @brief intersects two maps strip-wise, accumulating into a concurrent_vector
*
* @param[out] resultMap output map (must be allocated)
* @param[in] polymap1 map to be intersected
* @param[in] polymap2 map to be intersected
*/
void SplitParallelOverlayCV(concurrent_Polygon_map_t **result_map, Polygon_map_t *polymap1, Polygon_map_t *polymap2) {
int nthreads;
bool automatic_threadcount = false;
double domainSplitParallelTime;
tbb::tick_count t0, t1;
if(gThreadsLow == THREADS_UNSET || gThreadsLow == utility::get_default_num_threads() ) {
gThreadsLow = gThreadsHigh = utility::get_default_num_threads();
automatic_threadcount = true;
}
*result_map = new concurrent_Polygon_map_t;
RPolygon *p0 = &((*polymap1)[0]);
int mapxSize, mapySize, ignore1, ignore2;
p0->get(&ignore1, &ignore2, &mapxSize, &mapySize);
// (*result_map)->reserve(mapxSize*mapySize); // can't be any bigger than this
int grain_size;
#ifdef _DEBUG
grain_size = gMapXSize / 4;
#else
grain_size = gGrainSize;
#endif
for(nthreads = gThreadsLow; nthreads <= gThreadsHigh; nthreads++) {
tbb::global_control c(tbb::global_control::max_allowed_parallelism, nthreads);
if(gIsGraphicalVersion) {
RPolygon *xp = new RPolygon(0, 0, gMapXSize-1, gMapYSize-1, 0, 0, 0); // Clear the output space
delete xp;
}
// push the map size as the first polygon,
(*result_map)->push_back(RPolygon(0,0,mapxSize, mapySize));
t0 = tbb::tick_count::now();
tbb::parallel_for (blocked_range_with_maps<int>(0,(int)(mapxSize+1),grain_size, polymap1, polymap2), ApplySplitOverlayCV((*result_map), polymap1, polymap2));
t1 = tbb::tick_count::now();
domainSplitParallelTime = (t1-t0).seconds()*1000;
cout << "Splitting parallel with concurrent_vector and ";
if(automatic_threadcount) cout << "automatic";
else cout << nthreads;
cout << ((nthreads == 1) ? " thread" : " threads");
cout << " took " << domainSplitParallelTime << " msec : speedup over serial " << (gSerialTime / domainSplitParallelTime) << std::endl;
if(gCsvFile.is_open()) {
gCsvFile << "," << domainSplitParallelTime;
}
#if _DEBUG
{
Polygon_map_t s_result_map;
for(concurrent_Polygon_map_t::const_iterator ci = (*result_map)->begin(); ci != (*result_map)->end(); ++ci) {
s_result_map.push_back(*ci);
}
CheckPolygonMap(&s_result_map);
ComparePolygonMaps(&s_result_map, gResultMap);
}
#endif
(*result_map)->clear();
}
if(gCsvFile.is_open()) {
gCsvFile << std::endl;
}
}
// ------------------------------------------------------
class ApplySplitOverlayETS {
Polygon_map_t *m_map1, *m_map2;
ETS_Polygon_map_t *m_resultMap;
public:
/*!
* @brief functor for columnar parallel version
* @param[in] r range of map to be operated on
*/
void operator()(blocked_range_with_maps<int> & r) const {
// get yMapSize
int r1, g1, b1, r2, g2, b2;
int myr=-1;
int myg=-1;
int myb=-1;
int i1, i2, i3, yMapSize;
(*m_map1)[0].get(&i1, &i2, &i3, &yMapSize);
Flagged_map_t &fmap1 = r.map1();
Flagged_map_t &fmap2 = r.map2();
// When intersecting polygons from fmap1 and fmap2, if BOTH are flagged
// as duplicate, don't add the result to the output map. We can still
// intersect them, because we are keeping track of how much of the polygon
// is left over from intersecting, and quitting when the polygon is
// used up.
for(unsigned int ii=0; ii < fmap1.size(); ii++) {
RPolygon *p1 = fmap1[ii].p();
bool is_dup = fmap1[ii].isDuplicate();
int parea = p1->area();
p1->getColor(&r1, &g1, &b1);
for(unsigned int jj=0;(jj < fmap2.size()) && (parea > 0); jj++) {
int xl, yl, xh, yh;
RPolygon *p2 = fmap2[jj].p();
if(PolygonsOverlap(p1, p2, xl, yl, xh, yh)) {
if(!(is_dup && fmap2[jj].isDuplicate())) {
p2->getColor(&r2, &g2, &b2);
myr = r1 + r2;
myg = g1 + g2;
myb = b1 + b2;
(*m_resultMap).local().push_back(RPolygon(xl, yl, xh, yh, myr, myg, myb));
}
parea -= (xh-xl+1)*(yh-yl+1);
}
}
}
}
ApplySplitOverlayETS(ETS_Polygon_map_t *resultMap, Polygon_map_t *map1, Polygon_map_t *map2 ) :
m_resultMap(resultMap), m_map1(map1), m_map2(map2) {}
};
/*!
* @brief intersects two maps strip-wise, accumulating into an ets variable
*
* @param[out] resultMap output map (must be allocated)
* @param[in] polymap1 map to be intersected
* @param[in] polymap2 map to be intersected
*/
void SplitParallelOverlayETS(ETS_Polygon_map_t **result_map, Polygon_map_t *polymap1, Polygon_map_t *polymap2) {
int nthreads;
bool automatic_threadcount = false;
double domainSplitParallelTime;
tbb::tick_count t0, t1;
if(gThreadsLow == THREADS_UNSET || gThreadsLow == utility::get_default_num_threads() ) {
gThreadsLow = gThreadsHigh = utility::get_default_num_threads();
automatic_threadcount = true;
}
*result_map = new ETS_Polygon_map_t;
RPolygon *p0 = &((*polymap1)[0]);
int mapxSize, mapySize, ignore1, ignore2;
p0->get(&ignore1, &ignore2, &mapxSize, &mapySize);
// (*result_map)->reserve(mapxSize*mapySize); // can't be any bigger than this
int grain_size;
#ifdef _DEBUG
grain_size = gMapXSize / 4;
#else
grain_size = gGrainSize;
#endif
for(nthreads = gThreadsLow; nthreads <= gThreadsHigh; nthreads++) {
tbb::global_control c(tbb::global_control::max_allowed_parallelism, nthreads);
if(gIsGraphicalVersion) {
RPolygon *xp = new RPolygon(0, 0, gMapXSize-1, gMapYSize-1, 0, 0, 0); // Clear the output space
delete xp;
}
// push the map size as the first polygon,
// This polygon needs to be first, so we can push it at the start of a combine.
// (*result_map)->local.push_back(RPolygon(0,0,mapxSize, mapySize));
t0 = tbb::tick_count::now();
tbb::parallel_for (blocked_range_with_maps<int>(0,(int)(mapxSize+1),grain_size, polymap1, polymap2), ApplySplitOverlayETS((*result_map), polymap1, polymap2));
t1 = tbb::tick_count::now();
domainSplitParallelTime = (t1-t0).seconds()*1000;
cout << "Splitting parallel with ETS and ";
if(automatic_threadcount) cout << "automatic";
else cout << nthreads;
cout << ((nthreads == 1) ? " thread" : " threads");
cout << " took " << domainSplitParallelTime << " msec : speedup over serial " << (gSerialTime / domainSplitParallelTime) << std::endl;
if(gCsvFile.is_open()) {
gCsvFile << "," << domainSplitParallelTime;
}
#if _DEBUG
{
Polygon_map_t s_result_map;
flattened2d<ETS_Polygon_map_t> psv = flatten2d(**result_map);
s_result_map.push_back(RPolygon(0,0,mapxSize, mapySize));
for(flattened2d<ETS_Polygon_map_t>::const_iterator ci = psv.begin(); ci != psv.end(); ++ci) {
s_result_map.push_back(*ci);
}
CheckPolygonMap(&s_result_map);
ComparePolygonMaps(&s_result_map, gResultMap);
}
#endif
(*result_map)->clear();
}
if(gCsvFile.is_open()) {
gCsvFile << std::endl;
}
}

View File

@@ -0,0 +1,36 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*!
* polyover.h : extern declarations for polyover.cpp
*/
#include "rpolygon.h"
#include "tbb/spin_mutex.h"
extern void OverlayOnePolygonWithMap(Polygon_map_t *resultMap, RPolygon *myPoly, Polygon_map_t *map2, tbb::spin_mutex *rMutex);
extern void SerialOverlayMaps(Polygon_map_t **resultMap, Polygon_map_t *map1, Polygon_map_t *map2);
// extern void NaiveParallelOverlay(Polygon_map_t **result_map, Polygon_map_t *polymap1, Polygon_map_t *polymap2);
extern void NaiveParallelOverlay(Polygon_map_t *&result_map, Polygon_map_t &polymap1, Polygon_map_t &polymap2);
extern void SplitParallelOverlay(Polygon_map_t **result_map, Polygon_map_t *polymap1, Polygon_map_t *polymap2);
extern void SplitParallelOverlayCV(concurrent_Polygon_map_t **result_map, Polygon_map_t *polymap1, Polygon_map_t *polymap2);
extern void SplitParallelOverlayETS(ETS_Polygon_map_t **result_map, Polygon_map_t *polymap1, Polygon_map_t *polymap2);
extern void CheckPolygonMap(Polygon_map_t *checkMap);
extern bool ComparePolygonMaps(Polygon_map_t *map1, Polygon_map_t *map2);

View File

@@ -0,0 +1,89 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
//
// pover_global.h
//
#ifndef _POVER_GLOBAL_H_
#define _POVER_GLOBAL_H_
#ifdef _MAIN_C_
#define DEFINE // nothing
#define STATIC static
#define INIT(n) = n
#else // not in main file
#define DEFINE extern
#define STATIC // nothing
#define INIT(n) // nothing
#endif // _MAIN_C_
#include <iostream>
#include <fstream>
#ifdef _WINDOWS
#include <windows.h>
#endif
// this Polygon class only supports rectangles
DEFINE int gDrawXOffset INIT(0); // used for drawing polygons
DEFINE int gDrawYOffset INIT(0);
DEFINE int gPolyXBoxSize INIT(0); // number of pixels orresponding to one "square" (x)
DEFINE int gPolyYBoxSize INIT(0); // number of pixels orresponding to one "square" (y)
DEFINE bool gDoDraw INIT(false); // render the boxes
#define THREADS_UNSET 0
DEFINE int gThreadsLow INIT(THREADS_UNSET);
DEFINE int gThreadsHigh INIT(THREADS_UNSET);
DEFINE std::ofstream gCsvFile;
DEFINE double gSerialTime;
DEFINE char *gCsvFilename INIT(NULL);
#define BORDER_SIZE 10 // number of pixels between maps
// The map size and the number of polygons depends on the version we are compiling.
// If DEBUG then it is small; else it is large.
#ifdef _DEBUG
DEFINE int gNPolygons INIT(30); // default number of polygons in map
DEFINE int gMapXSize INIT(30);
DEFINE int gMapYSize INIT(30);
DEFINE int gGrainSize INIT(5);
#else
DEFINE int gNPolygons INIT(50000); // default number of polygons in map
DEFINE int gMapXSize INIT(1000);
DEFINE int gMapYSize INIT(1000);
DEFINE int gGrainSize INIT(20);
#endif
DEFINE int gMyRandomSeed INIT(2453185);
DEFINE bool gIsGraphicalVersion INIT(false);
typedef enum {
NORTH_SIDE,
EAST_SIDE,
SOUTH_SIDE,
WEST_SIDE
} allSides;
#if _DEBUG
#define PRINT_DEBUG(x) (cout << x << std::endl)
#else
#define PRINT_DEBUG(x)
#endif
#endif // _POVER_GLOBAL_H_

View File

@@ -0,0 +1,171 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Support for GUI display for Polygon overlay demo
#define VIDEO_WINMAIN_ARGS
#include <iostream>
#include "polyover.h"
#include "polymain.h"
#include "pover_video.h"
#include "tbb/tick_count.h"
#include "../../common/utility/get_default_num_threads.h"
#ifndef _WIN32
#include <sys/time.h>
#include <unistd.h>
void rt_sleep(int msec) {
usleep(msec*1000);
}
#else //_WIN32
#undef OLDUNIXTIME
#undef STDTIME
#include <windows.h>
void rt_sleep(int msec) {
Sleep(msec);
}
#endif /* _WIN32 */
using namespace std;
bool g_next_frame() {
if(++n_next_frame_calls >= frame_skips) { // the data race here is benign
n_next_frame_calls = 0;
return gVideo->next_frame();
}
return gVideo->running;
}
bool g_last_frame() {
if(n_next_frame_calls) return gVideo->next_frame();
return gVideo->running;
}
bool initializeVideo(int argc, char **argv) {
//pover_video *l_video = new pover_video();
//gVideo = l_video;
gVideo->init_console(); // don't check return code.
gVideo->title = g_windowTitle;
g_useGraphics = gVideo->init_window(g_xwinsize, g_ywinsize);
return true;
}
void pover_video::on_process() {
tbb::tick_count t0, t1;
double naiveParallelTime, domainSplitParallelTime;
// create map1 These could be done in parallel, if the pseudorandom number generator were re-seeded.
GenerateMap(&gPolymap1, gMapXSize, gMapYSize, gNPolygons, /*red*/255, /*green*/0, /*blue*/127);
// create map2
GenerateMap(&gPolymap2, gMapXSize, gMapYSize, gNPolygons, /*red*/0, /*green*/255, /*blue*/127);
//
// Draw source maps
gDrawXOffset = map1XLoc;
gDrawYOffset = map1YLoc;
for(int i=0; i < int(gPolymap1->size()); i++) {
(*gPolymap1)[i].drawPoly();
}
gDrawXOffset = map2XLoc;
gDrawYOffset = map2YLoc;
for(int i=0; i < int(gPolymap2->size()) ;i++) {
(*gPolymap2)[i].drawPoly();
}
gDoDraw = true;
// run serial map generation
gDrawXOffset = maprXLoc;
gDrawYOffset = maprYLoc;
{
RPolygon *xp = new RPolygon(0, 0, gMapXSize-1, gMapYSize-1, 0, 0, 0); // Clear the output space
delete xp;
t0 = tbb::tick_count::now();
SerialOverlayMaps(&gResultMap, gPolymap1, gPolymap2);
t1 = tbb::tick_count::now();
cout << "Serial overlay took " << (t1-t0).seconds()*1000 << " msec" << std::endl;
gSerialTime = (t1-t0).seconds()*1000;
#if _DEBUG
CheckPolygonMap(gResultMap);
// keep the map for comparison purposes.
#else
delete gResultMap;
#endif
if(gCsvFile.is_open()) {
gCsvFile << "Serial Time," << gSerialTime << std::endl;
gCsvFile << "Threads,";
if(gThreadsLow == THREADS_UNSET || gThreadsLow == utility::get_default_num_threads()) {
gCsvFile << "Threads,Automatic";
}
else {
for(int i=gThreadsLow; i <= gThreadsHigh; i++) {
gCsvFile << i;
if(i < gThreadsHigh) gCsvFile << ",";
}
}
gCsvFile << std::endl;
}
if(gIsGraphicalVersion) rt_sleep(2000);
}
// run naive parallel map generation
{
Polygon_map_t *resultMap;
if(gCsvFile.is_open()) {
gCsvFile << "Naive Time";
}
NaiveParallelOverlay(resultMap, *gPolymap1, *gPolymap2);
delete resultMap;
if(gIsGraphicalVersion) rt_sleep(2000);
}
// run split map generation
{
Polygon_map_t *resultMap;
if(gCsvFile.is_open()) {
gCsvFile << "Split Time";
}
SplitParallelOverlay(&resultMap, gPolymap1, gPolymap2);
delete resultMap;
if(gIsGraphicalVersion) rt_sleep(2000);
}
// split, accumulating into concurrent vector
{
concurrent_Polygon_map_t *cresultMap;
if(gCsvFile.is_open()) {
gCsvFile << "Split CV time";
}
SplitParallelOverlayCV(&cresultMap, gPolymap1, gPolymap2);
delete cresultMap;
if(gIsGraphicalVersion) rt_sleep(2000);
}
// split, accumulating into ETS
{
ETS_Polygon_map_t *cresultMap;
if(gCsvFile.is_open()) {
gCsvFile << "Split ETS time";
}
SplitParallelOverlayETS(&cresultMap, gPolymap1, gPolymap2);
delete cresultMap;
if(gIsGraphicalVersion) rt_sleep(2000);
}
if(gIsGraphicalVersion) rt_sleep(8000);
delete gPolymap1;
delete gPolymap2;
#if _DEBUG
delete gResultMap;
#endif
}

View File

@@ -0,0 +1,60 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// support for GUI for polygon overlay demo
//
#ifndef _POVER_VIDEO_H_
#define _POVER_VIDEO_H_
#include "../../common/gui/video.h"
#include "pover_global.h" // for declaration of DEFINE and INIT
DEFINE class video *gVideo INIT(0);
DEFINE int n_next_frame_calls INIT(0);
DEFINE int frame_skips INIT(10);
extern bool g_next_frame();
extern bool g_last_frame();
class pover_video: public video {
void on_process();
public:
#ifdef _WINDOWS
bool graphic_display(){return video::win_hInstance != (HINSTANCE)NULL;}
#else
bool graphic_display() { return true;} // fix this for Linux
#endif
//void on_key(int key);
};
DEFINE int g_xwinsize INIT(1024);
DEFINE int g_ywinsize INIT(768);
DEFINE int map1XLoc INIT(10);
DEFINE int map1YLoc INIT(10);
DEFINE int map2XLoc INIT(270);
DEFINE int map2YLoc INIT(10);
DEFINE int maprXLoc INIT(530);
DEFINE int maprYLoc INIT(10);
DEFINE const char *g_windowTitle INIT("Polygon Overlay");
DEFINE bool g_useGraphics INIT(true);
extern bool initializeVideo(int argc, char **argv);
extern void rt_sleep(int msec);
#endif // _POVER_VIDEO_H_

View File

@@ -0,0 +1,476 @@
<!DOCTYPE html>
<html xmlns:mso="urn:schemas-microsoft-com:office:office" xmlns:msdt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882">
<head>
<meta charset="UTF-8">
<style>
::selection {
background: #b7ffb7;
}
::-moz-selection {
background: #b7ffb7;
}
body {
font-family: Arial, Helvetica, sans-serif;
font-size: 16px;
width: 800px;
margin: 0 auto;
}
#banner {
/* Div for banner */
float:left;
margin: 0px;
margin-bottom: 10px;
width: 100%;
background-color: #0071C5;
z-index: 0;
}
#banner .logo {
/* Apply to logo in banner. Add as class to image tag. */
float: left;
margin-right: 20px;
margin-left: 20px;
margin-top: 15px;
padding-bottom: 5px;
}
h1 {
text-align: center;
font-size: 36px;
}
h1.title {
/* Add as class to H1 in banner */
font-family: "Intel Clear", Verdana, Arial, sans-serif;
font-weight:normal;
color: #FFFFFF;
font-size: 170%;
margin-right: 40px;
margin-left: 40px;
padding-right: 20px;
text-indent: 20px;
}
.h3-alike {
display:inline;
font-size: 1.17em;
font-weight: bold;
color: #0071C5;
}
h3 {
font-size: 1.17em;
font-weight: bold;
color: #0071C5;
}
.h4-alike {
display:inline;
font-size: 1.05em;
font-weight: bold;
}
pre {
font-family: "Consolas", Monaco, monospace;
font-size:small;
background: #fafafa;
margin: 0;
padding-left:20px;
}
#footer {
font-size: small;
}
code {
font-family: "Consolas", Monaco, monospace;
}
.code-block
{
padding-left:20px;
}
.changes {
margin: 1em 0;
}
.changes input:active {
position: relative;
top: 1px;
}
.changes input:hover:after {
padding-left: 16px;
font-size: 10px;
content: 'More';
}
.changes input:checked:hover:after {
content: 'Less';
}
.changes input + .show-hide {
display: none;
}
.changes input:checked + .show-hide {
display: block;
}
ul {
margin: 0;
padding: 0.5em 0 0.5em 2.5em;
}
ul li {
margin-bottom: 3px;
}
ul li:last-child {
margin-bottom: 0;
}
.disc {
list-style-type:disc
}
.circ {
list-style-type:circle
}
.single {
padding: 0 0.5em;
}
/* ------------------------------------------------- */
/* Table styles */
table{
margin-bottom:5pt;
border-collapse:collapse;
margin-left:0px;
margin-top:0.3em;
font-size:10pt;
}
tr{
vertical-align:top;
}
th,
th h3{
padding:4px;
text-align:left;
background-color:#0071C5;
font-weight:bold;
margin-top:1px;
margin-bottom:0;
color:#FFFFFF;
font-size:10pt;
vertical-align:middle;
}
th{
border:1px #dddddd solid;
padding-top:2px;
padding-bottom:0px;
padding-right:3px;
padding-left:3px;
}
td{
border:1px #dddddd solid;
vertical-align:top;
font-size:100%;
text-align:left;
margin-bottom:0;
}
td,
td p{
margin-top:0;
margin-left:0;
text-align:left;
font-size:inherit;
line-height:120%;
}
td p{
margin-bottom:0;
padding-top:5px;
padding-bottom:5px;
padding-right:5px;
padding-left:1px;
}
.noborder{
border:0px none;
}
.noborder1stcol{
border:0px none;
padding-left:0pt;
}
td ol{
font-size:inherit;
margin-left:28px;
}
td ul{
font-size:inherit;
margin-left:24px;
}
.DefListTbl{
width:90%;
margin-left:-3pt;
}
.syntaxdiagramtbl{
margin-left:-3pt;
}
.sdtbl{
}
.sdrow{
}
.sdtblp{
border:0px none;
font-size:inherit;
line-height:120%;
margin-bottom:0;
padding-bottom:0px;
padding-top:5px;
padding-left:0px;
padding-right:5px;
vertical-align:top;
}
.idepara, .ide_para{
border:0px none;
font-size:inherit;
line-height:120%;
margin-bottom:0;
padding-bottom:0px;
padding-top:5px;
padding-left:0px;
padding-right:5px;
vertical-align:top;
}
.specs {
border-collapse:collapse;
}
.specs td, .specs th {
font-size: 14px;
}
.specs td {
border: 1px solid black;
}
.specs td td, .specs td th {
border: none;
}
.specs td, .specs td td, .specs td th {
padding: 0 0.2em 0.2em;
text-align: center;
}
.specs td tr:last-child td,
.specs td tr:last-child th {
padding: 0 0.2em;
}
.serial-time {
}
.modified-time {
width: 6.5em;
}
.compiler {
}
.comp-opt {
}
.sys-specs {
width: 18em;
}
.note {
font-size:small;
font-style: italic;
}
</style>
<title>Intel&reg; Threading Building Blocks. Polygon_overlay sample</title>
</head>
<body>
<div id="banner">
<img class="logo" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEMAAAAsCAYAAAA+aAX8AAAAAXNSR0IArs4c6QAAAARnQU1BAACx
jwv8YQUAAAAJcEhZcwAALiIAAC4iAari3ZIAAAAZdEVYdFNvZnR3YXJlAEFkb2JlIEltYWdlUmVh
ZHlxyWU8AAAIN0lEQVRoQ+WaCaxdUxSGW2ouatZWaVS15nkqkZhSVERQglLEPCam1BCixhqqCKUS
NIiYpxhqHmouIeaY5ylFzA/v1fev8+/j3N5737v3vtf3buNP/uy9/7X2Ovuse4a997m9mgltbW2L
wRHwcHgFfAx+AH+GCb/BT2fNmvUk5ZXwYOrrOsTcCU5CJ74pPBJeA5+Bn8LfOLmagf/f8Af4NrwD
ngg3wdTHh2pOMMB1Gejx8AE4M85mNqD/A7+D78GXkXQFTIMPwUfhdPg6/AxWTRw29b8QruPD9zwY
zPrwHPi2xxmg3QrfgDfD05BGU24EB1HvC3s7REXgtwDsDzeEY+Ak+AJsUfwE2sJdcBN37V4whiU4
+KGUM2JEBtpzUInZEa5g9y4FcYfAo+GLPmwOND2HFrXrnAUHWgnq0vzDB2+Bt0H9coPs1m3gmNvD
ZyITBu234Jp26XoQfCC80sfTAXVv7wOXskuPgnHoSvnTw9P49MDdyOauAQEXhWdC4Vd4ARxmc1OB
cW0Gv3U+lJDvKFa0ufMg4GXwR3gs7J57sRNoaWnR2+znLB2RkKds6jwItvbckIQiGO+eTkSby71t
qh100qtsUCJxmmpSw5i2gWebR1jWm2047T1gf0vyfViJEKi/TtHua7wMdNJs8U/zDzjUpqYA47k4
O704wY+kUZ2P+glQc5ldac9j323sF1cH2EB6h8BxYZdbRDeDOJ16UBJiHDFuMMdYbhjEGA8DxJ4h
jXIemmMpz6ccqbZ1JUlT/3SrHC+9XeB0MjzV9RHqKFAXVg2nBkH/lxxO8aZYbhjEKEuGQH1BuCKc
z1IAN61jAtiut1wZ+ByIkwa6r9t6ZmhSFZw9eL0gxiMw4SLLDYMYFZNRDbhpcpgwzXI5MOqSEvKM
Ue8D+xU4r/Xe+C8HB1ThkhFgNqAXk6FVqyZuA1LcItBXQd+WUvf6YMslwFZvMs7KvMP/SculwKa3
hfYPPsZpfsvS9QD9PRHbcOmUC9J+H2qfoRJ/0MHgFhHIQC8mQ8twxZ0Ji099vSGegn/TP0BdD/Db
Ycn0nna9yZiceQcetFwKDE/4oNtZCtDeXHoC7dWlU1Uyvs7U6sBHJ7FaBAPU82TYJUAzFnCU+1mq
COyfwGLi6k3G05l34BrL/wFxjA/0mKUcaNqBKiJODHclQ3sLCVqZprfEvVCLtThhiskRDFAvXhnv
QPlfi5uW7ytTL14Nr0Bd1pfDXy1Lv93h6koGLstCLR/SuPJ5SQBBD8hPZATbWs6BrdZk7B4dDNpT
Mjkw3bL0YjLOsxygPUWDyExtD1GNV6JAeyTUBlDCKtbrScYxhfjyj1s+B9o+dnifIj94AnpNyaC9
f3QwkNJCTnjOsvRiMi6xrHiaA3ycyYFNbcqBpisl/aoHWaspGdg03uIc43mb/gOilt3CREslQG80
GedmlkC1KyNPBnU9wOPWMp6Aut0S74HfwIQJ7ldTMjBPdBIiGWC0TRkQlseWNmR2tlwC9DmZjEmW
pQ/zOAKqtwdcrnW/DpOBPtp9Ii6F9lhL1yWIo2zUvVhxzYHeLVcG/QfT/iuTA3qwan+zGndVP8p2
k4G8E/wLW4D6PxTlnxgwaDEjaMe6n+USYOvqZKTbUrjQcor3ZSYHRtjULvCrmgwkfY5oRc9B+3Cb
S4FhIhS+gAtZLgH9Y6GWuQU6mwx9IEqYajlA+47CsZ6lGovFBDTNkA9xM4CmpXsAWySDUrPjqZQl
QBsfnSoB41UKAvS9ouJmDfpaDpTQ2WRcXYinCZm+pdyEtDClPgLloP0unABPp3lrpoZ+KkWskSgP
sVZMhlat2t7LQftE2aoCh0sVBOheXclyCYjTp7W19bUsZAQtJuPLTA39gOhg0D7PJtny1xj1tWA+
sUpAG2j7mZaqAh9tzPSVP+XStL+w/qY1XRlfWdOSYXvp7QKnU6Ayqk4jLZcB2zD4gv1iu52qkvG5
NKPsyrCuPs9aDtDeDr4EtS7RRyXNCgfYLPtYfoC33D0Hul6tE6jOfvsMhVqaT8PWG85PXR+WxlOP
pHUIHPNXDsif7NWAT773STdlX6vK4ebi4WRgWybZqFe86tBXUAw4BL+S7UTautTXo9yFcjdKPbsq
PuQTsKdbZ16YLzZrAgdRRvXLCF/Big/R/wXInn5dffdMt8opNs214Bz6cyqNbUDRcZwTIWjDt3m+
XtcBxq3pvL6p6mFftlFUE+i8JPxRCRGoawVbcVepGcF4V4eTGPNPHv+7NjUGAhzmQOl20fyhphlg
T4CxLcQw9WC9Gxb3P4Q37NY4CHJXCuhSW3JnwEXs0qNgSHqVbw210ZP2XwK0A65/6C6NgziaAU5X
wCIUHB4H86227gKH1+JtL3gd1N5sCdACbgZo5rtgnQKx+hLs/ixsdjBXBd2TtyKNhUOp1/dprgMQ
rx9x16fcn1KbttrIyf9OkICWw1KApvY2YyXbpSBobKf7OGXApFtI+5d3Qq1BDoL6V87GcDVc9Ivq
E4D+bjTQbc1i9demreDu8Ch0ffG6hdnmDMrvFbsSsAXczIGk3fwb4VYe+pwBB9Angkd83ADtqgkq
AjetdTTV1icDlfl+Qi3AP4elHEjaDXscHgFjPdNt4ID6S9B9sNLiKoelmuFuJbCpDJi+hvqz2qFw
iIfWc2AQusxPgvq484vH2eUgtpYHH0Hteeqb75ZwMQ+j+cDg9PlwFDwd6o9sr0KtbWI/tSPgp32M
76H+s6mNX3030df5neGq1OtbZDUbOIlFoFaha0L9j0qfCHeAerDqVtODU8+hNThZfR1fHHbpG6kx
9Or1LzUmVVz+HJXDAAAAAElFTkSuQmCC">
<h1 class="title">Intel&reg; Threading Building Blocks.<br>Polygon_overlay sample</h1>
</div>
<p>
Polygon Overlay example that demonstrates the use of parallel_for.
<br><br>
This example is a simple implementation of polygon overlay, as described in
<a href="http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.46.9538">
<i>Parallelizing the Polygon Overlay Problem Using Orca</i>, by H.F. Langendoen</a>.
<br><br>
The solution was implemented in three forms:
<ul>
<li>The naive serial solution.
<li>The naive parallel solution, by splitting list of polygons from one map and intersecting
each sub-list against the entire list of polygons from the second map.
<li>A parallel solution where each map is split into submaps, with each resulting submap being
intersected against the corresponding submap from the other map. This solution requires some
redundancy (some polygons are members of more than one submap). To prevent multiple copies
of a polygon from being placed in the solution map, if both polygons are duplicated (that is,
if they both appear in more than one map), they are intersected but the result is not placed
in the solution map.
</ul>
The only optimization in each solution is that the area of the generated sub-polygons are subtracted from
the original area of one of the source polygons. When the remaining area is zero, the intersection process
is halted.
<br><br>
<i>A word about the speedup of the submap case.</i> One may get superlinear speedup in this case (for instance a
laptop with Intel&reg; Core(TM) Duo processor got a speedup of about 20 percent over serial.) This results from two effects:
<ul>
<li>the number of threads used, and
<li>the fact that for each submap, the number of polygons is smaller than that for the other two cases.
</ul>
If there are, say, 400 polygons in each map, then on average the number of intersections calculated is
approximately 80,000 (400 * 200, where 200 is the average number of polygons examined before stopping.)
If the maps are split into 2 submaps, the time for each submap is about 200*100, or 20,000. So even
comparing the two sets of submaps serially should result in a speedup somewhere around 2. This number
is affected by the number of redundant polygons being compared; this effect would eventually swamp the gain
from comparing smaller numbers of polygons per submap. And remember the submaps are created by intersecting each
map with a rectangular polygon covering the submap being generated, which is additional work taking about N * O(400)
in the case above, where N is the number of submaps generated, that can be done in parallel.
<br><br>
Running the default release pover while varying the number of submaps from 1 to 1000, the speedup on the submap
case for a 2-processor system looks like
<br><br>
<img src="speedup.gif" alt="Table of speedup for the algorithm">
<br><br>
One further optimization would be to sort one map, say <b>map1</b>, by maxY, and sort the other map (<b>map2</b>)
by minY. For <b>p1</b> in <b>map1</b>, start testing for intersection at the first <b>p2</b> in <b>map2</b>
that intersected the last polygon tested in <b>map1</b>. This would speed up the intersection process greatly,
but the optimization would apply to all the methods, and the sort would have to be accounted for in the timing.
<br><br>
The source maps are generated pseudo-randomly in the manner described in the paper above. That is, if
we need N polygons, then N "boxes" are chosen at random, then one-at-a-time the areas are expanded in
one of fours directions until the area hits an adjacent polygon. When this process is finished, the
resulting map is inspected and any remaining unoccupied "boxes" are made into additional polygons, as
large as possible in each case. So the actual number of polygons in each map will in general be larger
than the number of polygons requested (sometimes by 10% or more.)
<br><br>
One limitation of the program is that if the number of polygons in the source map is greater than the number of
"boxes" (pixels in the GUI case), the maps cannot be generated.
</p>
<div class="changes">
<div class="h3-alike">System Requirements</div>
<input type="checkbox">
<div class="show-hide">
<p>
For the most up to date system requirements, see the <a href="http://software.intel.com/en-us/articles/intel-threading-building-blocks-release-notes">release notes.</a>
</p>
</div>
</div>
<div class="changes">
<div class="h3-alike">Files</div>
<input type="checkbox" checked="checked">
<div class="show-hide">
<dl>
<dt><a href="polyover.cpp">polyover.cpp</a>
<dd>Source code for main program.
<dt><a href="polyover.h">polyover.h</a>
<dd>Global variables, classes and enums.
<dt><a href="pover_video.cpp">pover_video.cpp</a>
<dd>Source code for the GUI interface.
<dt><a href="pover_video.h">pover_video.h</a>
<dd>Defines for the GUI version.
<dt><a href="Makefile">Makefile</a>
<dd>Makefile for building the example.
</dl>
</div>
</div>
<div class="changes">
<div class="h3-alike">Directories</div>
<input type="checkbox" checked="checked">
<div class="show-hide">
<dl>
<dt><a href="msvs/">msvs</a>
<dd>Contains Microsoft* Visual Studio* workspace for building and running the example (Windows* systems only).
<dt><a href="xcode/">xcode</a>
<dd>Contains Xcode* IDE workspace for building and running the example (macOS* systems only).
</dl>
<p>For information about the minimum supported version of IDE, see <a href="http://software.intel.com/en-us/articles/intel-threading-building-blocks-release-notes">release notes.</a></p>
</div>
</div>
<div class="changes">
<div class="h3-alike">Build instructions</div>
<input type="checkbox" checked="checked">
<div class="show-hide">
<p>
General build directions can be found <a href="../../index.html">here</a>.
<br><br>
For the various UI options, see the <a href="../../common/index.html">common GUI code</a> build instructions.
</p>
</div>
</div>
<div class="changes">
<div class="h3-alike">Usage</div>
<input type="checkbox" checked="checked">
<div class="show-hide">
<p>
Building via the above make commands, or via Microsoft* Visual Studio* projects on Windows* systems, produces executable files
named pover.exe. To run these executables directly, use one or more of the following commands:
</p>
<dl>
<dt><tt>pover.exe</tt>
<dd>Run this version (release or debug).
<dt><tt>pover.exe n:m</tt>
<dd>Run this version (release or debug) (m-n+1) times, with n threads to m threads inclusive.
<dt>To run a short version of this example, e.g., for use with Intel&reg; Threading Tools:
<dd>Build a <i>debug</i> version with the GUI turned off
(e.g., <tt>make UI=con debug</tt>; see also the build directions above).
<br>Run it with a small dataset, e.g., <tt>pover.exe&nbsp;--polys&nbsp;10&nbsp;--size&nbsp;5x5</tt>.
</dl>
</div>
</div>
<div class="changes">
<div class="h3-alike">Notes</div>
<input type="checkbox" checked="checked">
<div class="show-hide">
<ul>
<li>While running with the GUI display should yield reasonable performance in most cases, <i>running with no GUI
display is strongly recommended</i> in order to demonstrate the full performance and scalability of the example.
</ul>
</div>
</div>
<br>
<a href="../index.html">Up to parent directory</a>
<hr>
<div class="changes">
<div class="h3-alike">Legal Information</div>
<input type="checkbox">
<div class="show-hide">
<p>
Intel, Intel Core and the Intel logo are trademarks of Intel Corporation in the U.S. and/or other countries.
<br>* Other names and brands may be claimed as the property of others.
<br>&copy; 2020, Intel Corporation
</p>
</div>
</div>
</body>
</html>

View File

@@ -0,0 +1,151 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// rpolygon.h
//
#ifndef _RPOLYGON_H_
#define _RPOLYGON_H_
#include <vector>
#include <iostream>
#include "pover_video.h"
#include "tbb/scalable_allocator.h"
#include "tbb/concurrent_vector.h"
#include "tbb/enumerable_thread_specific.h"
using namespace std;
using namespace tbb;
class RPolygon;
typedef scalable_allocator<RPolygon> RPolygon_allocator;
DEFINE RPolygon_allocator rAlloc;
enum MallocBehavior {
UseMalloc,
UseScalableAllocator
};
DEFINE MallocBehavior gMBehavior INIT(UseScalableAllocator);
class RPolygon {
public:
RPolygon() {m_XMin = m_YMin = m_XMax = m_YMax = 0;
m_r = m_g = m_b = 0;
}
RPolygon(int xMin, int yMin, int xMax, int yMax, int r=-1, int g=-1, int b=-1) : m_XMin(xMin), m_YMin(yMin), m_XMax(xMax), m_YMax(yMax) {
if( r >= 0) {
m_r=(colorcomp_t)r; m_g=(colorcomp_t)g; m_b=(colorcomp_t)b;
if(gDoDraw) drawPoly();
}
}
void set_nodraw(int xMin, int yMin, int xMax, int yMax) {m_XMin=xMin; m_YMin=yMin; m_XMax=xMax; m_YMax=yMax;}
RPolygon &intersect(RPolygon &otherPoly);
void set(int xMin, int yMin, int xMax, int yMax) {
set_nodraw(xMin,yMin,xMax,yMax);
if(gDoDraw) {
drawPoly();
}
}
void get(int *xMin, int *yMin, int *xMax, int *yMax) const {*xMin=m_XMin;*yMin=m_YMin;*xMax=m_XMax;*yMax=m_YMax;}
int xmax() const { return m_XMax; }
int xmin() const { return m_XMin; }
int ymax() const { return m_YMax; }
int ymin() const { return m_YMin; }
void setColor(colorcomp_t newr, colorcomp_t newg, colorcomp_t newb) {m_r = newr; m_g=newg; m_b=newb;}
void getColor(int *myr, int *myg, int *myb) {*myr=m_r; *myg=m_g; *myb=m_b;}
color_t myColor() {return gVideo->get_color(m_r, m_g, m_b);}
void drawPoly() {
if(gVideo->running) {
if(g_next_frame()) { // Shouldn't call next_frame each time
drawing_area ldrawing(
gDrawXOffset+m_XMin*gPolyXBoxSize, //x
gDrawYOffset+m_YMin*gPolyYBoxSize, //y
(m_XMax-m_XMin+1)*gPolyXBoxSize, //sizex
(m_YMax-m_YMin+1)*gPolyYBoxSize); //sizey
for(int y=0; y<ldrawing.size_y; y++) {
ldrawing.set_pos(0,y);
color_t my_color = myColor();
for(int x=0;x < ldrawing.size_x; x++) {
ldrawing.put_pixel(my_color);
}
}
}
}
}
int area() {return ((m_XMax-m_XMin+1)*(m_YMax-m_YMin+1));}
void print(int i) { cout << "RPolygon " << i << " (" << m_XMin << ", " << m_YMin << ")-(" << m_XMax << ", " << m_YMax << ") " << endl; fflush(stdout);}
private:
int m_XMin;
int m_YMin;
int m_XMax;
int m_YMax;
colorcomp_t m_r;
colorcomp_t m_g;
colorcomp_t m_b;
};
#if _MAIN_C_
bool operator<(const RPolygon& a, const RPolygon& b) {
if(a.ymin() > b.ymin()) return false;
if(a.ymin() < b.ymin()) return true;
return a.xmin() < b.xmin();
}
#else
extern bool operator<(const RPolygon& a, const RPolygon& b);
#endif
extern ostream& operator<<(ostream& s, const RPolygon &p);
class RPolygon_flagged {
RPolygon *myPoly;
bool is_duplicate;
public:
RPolygon_flagged() {myPoly = NULL; is_duplicate = false;}
RPolygon_flagged(RPolygon* _p, bool _is_duplicate) : myPoly(_p), is_duplicate(_is_duplicate) { }
bool isDuplicate() {return is_duplicate;}
void setDuplicate(bool newValue) {is_duplicate = newValue;}
RPolygon *p() {return myPoly;}
void setp(RPolygon *newp) {myPoly = newp;}
};
typedef class vector<RPolygon, RPolygon_allocator> Polygon_map_t;
typedef class concurrent_vector<RPolygon, RPolygon_allocator> concurrent_Polygon_map_t;
typedef class enumerable_thread_specific<Polygon_map_t> ETS_Polygon_map_t;
typedef class vector<RPolygon_flagged, scalable_allocator<RPolygon_flagged> > Flagged_map_t; // we'll make shallow copies
inline bool PolygonsOverlap(RPolygon *p1, RPolygon *p2, int &xl, int &yl, int &xh, int &yh) {
int xl1, yl1, xh1, yh1, xl2, yl2, xh2, yh2;
#if _DEBUG
rt_sleep(1); // slow down the process so we can see it.
#endif
p1->get(&xl1, &yl1, &xh1, &yh1);
p2->get(&xl2, &yl2, &xh2, &yh2);
if(xl1 > xh2) return false;
if(xh1 < xl2) return false;
if(yl1 > yh2) return false;
if(yh1 < yl2) return false;
xl = (xl1 < xl2) ? xl2 : xl1;
xh = (xh1 < xh2) ? xh1 : xh2;
yl = (yl1 < yl2) ? yl2 : yl1;
yh = (yh1 < yh2) ? yh1 : yh2;
return true;
}
#endif // _RPOLYGON_H_

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.0 KiB

View File

@@ -0,0 +1,573 @@
// !$*UTF8*$!
{
archiveVersion = 1;
classes = {
};
objectVersion = 46;
objects = {
/* Begin PBXBuildFile section */
84B8DA77152CA90100D59B95 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 84B8DA6F152CA90100D59B95 /* main.m */; };
84B8DA78152CA90100D59B95 /* OpenGLView.m in Sources */ = {isa = PBXBuildFile; fileRef = 84B8DA71152CA90100D59B95 /* OpenGLView.m */; };
84B8DA79152CA90100D59B95 /* tbbAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 84B8DA73152CA90100D59B95 /* tbbAppDelegate.m */; };
84B8DA7A152CA90100D59B95 /* (null) in Resources */ = {isa = PBXBuildFile; };
84B8DA80152CA97B00D59B95 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 84B8DA7C152CA97B00D59B95 /* InfoPlist.strings */; };
84B8DA81152CA97B00D59B95 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 84B8DA7E152CA97B00D59B95 /* MainMenu.xib */; };
84B8DA9A152CADF400D59B95 /* macvideo.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 84B8DA99152CADF400D59B95 /* macvideo.cpp */; };
84B8DAAC152CB05200D59B95 /* polymain.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 84B8DAA4152CB05200D59B95 /* polymain.cpp */; };
84B8DAAD152CB05200D59B95 /* polyover.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 84B8DAA6152CB05200D59B95 /* polyover.cpp */; };
84B8DAAE152CB05200D59B95 /* pover_video.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 84B8DAA9152CB05200D59B95 /* pover_video.cpp */; };
84D017561527431F0008A4E0 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 84D017551527431F0008A4E0 /* Cocoa.framework */; };
84D01776152744BD0008A4E0 /* OpenGL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 84D01775152744BD0008A4E0 /* OpenGL.framework */; };
D31F32621C11DEE000A77D54 /* polymain.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 84B8DAA4152CB05200D59B95 /* polymain.cpp */; };
D31F32631C11DEE300A77D54 /* polyover.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 84B8DAA6152CB05200D59B95 /* polyover.cpp */; };
D31F32641C11DEE700A77D54 /* pover_video.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 84B8DAA9152CB05200D59B95 /* pover_video.cpp */; };
D31F32651C11DEEC00A77D54 /* macvideo.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 84B8DA99152CADF400D59B95 /* macvideo.cpp */; };
D31F32661C11DEF000A77D54 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 84B8DA6F152CA90100D59B95 /* main.m */; };
D31F32671C11DEF300A77D54 /* OpenGLView.m in Sources */ = {isa = PBXBuildFile; fileRef = 84B8DA71152CA90100D59B95 /* OpenGLView.m */; };
D31F32681C11DEF600A77D54 /* tbbAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 84B8DA73152CA90100D59B95 /* tbbAppDelegate.m */; };
D31F326B1C11DF6000A77D54 /* iOS.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = D31F32691C11DF1600A77D54 /* iOS.storyboard */; };
/* End PBXBuildFile section */
/* Begin PBXBuildRule section */
C3C5897B2191EB8300DAC94C /* PBXBuildRule */ = {
isa = PBXBuildRule;
compilerSpec = com.intel.compilers.icc.latest;
fileType = sourcecode.cpp;
isEditable = 1;
outputFiles = (
);
script = "# Type a script or drag a script file from your workspace to insert its path.\n";
};
/* End PBXBuildRule section */
/* Begin PBXFileReference section */
84B8DA6F152CA90100D59B95 /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = main.m; path = ../../../common/gui/xcode/tbbExample/main.m; sourceTree = "<group>"; };
84B8DA70152CA90100D59B95 /* OpenGLView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OpenGLView.h; path = ../../../common/gui/xcode/tbbExample/OpenGLView.h; sourceTree = "<group>"; };
84B8DA71152CA90100D59B95 /* OpenGLView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OpenGLView.m; path = ../../../common/gui/xcode/tbbExample/OpenGLView.m; sourceTree = "<group>"; };
84B8DA72152CA90100D59B95 /* tbbAppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = tbbAppDelegate.h; path = ../../../common/gui/xcode/tbbExample/tbbAppDelegate.h; sourceTree = "<group>"; };
84B8DA73152CA90100D59B95 /* tbbAppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = tbbAppDelegate.m; path = ../../../common/gui/xcode/tbbExample/tbbAppDelegate.m; sourceTree = "<group>"; };
84B8DA75152CA90100D59B95 /* tbbExample-Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "tbbExample-Prefix.pch"; path = "../../../common/gui/xcode/tbbExample/tbbExample-Prefix.pch"; sourceTree = "<group>"; };
84B8DA7D152CA97B00D59B95 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = InfoPlist.strings; sourceTree = "<group>"; };
84B8DA7F152CA97B00D59B95 /* en */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = en; path = MainMenu.xib; sourceTree = "<group>"; };
84B8DA99152CADF400D59B95 /* macvideo.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = macvideo.cpp; path = ../../../common/gui/macvideo.cpp; sourceTree = "<group>"; };
84B8DAA4152CB05200D59B95 /* polymain.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = polymain.cpp; path = ../polymain.cpp; sourceTree = "<group>"; };
84B8DAA5152CB05200D59B95 /* polymain.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = polymain.h; path = ../polymain.h; sourceTree = "<group>"; };
84B8DAA6152CB05200D59B95 /* polyover.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = polyover.cpp; path = ../polyover.cpp; sourceTree = "<group>"; };
84B8DAA7152CB05200D59B95 /* polyover.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = polyover.h; path = ../polyover.h; sourceTree = "<group>"; };
84B8DAA8152CB05200D59B95 /* pover_global.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = pover_global.h; path = ../pover_global.h; sourceTree = "<group>"; };
84B8DAA9152CB05200D59B95 /* pover_video.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = pover_video.cpp; path = ../pover_video.cpp; sourceTree = "<group>"; };
84B8DAAA152CB05200D59B95 /* pover_video.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = pover_video.h; path = ../pover_video.h; sourceTree = "<group>"; };
84B8DAAB152CB05200D59B95 /* rpolygon.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = rpolygon.h; path = ../rpolygon.h; sourceTree = "<group>"; };
84D017511527431F0008A4E0 /* tbbExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = tbbExample.app; sourceTree = BUILT_PRODUCTS_DIR; };
84D017551527431F0008A4E0 /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = System/Library/Frameworks/Cocoa.framework; sourceTree = SDKROOT; };
84D017581527431F0008A4E0 /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = System/Library/Frameworks/AppKit.framework; sourceTree = SDKROOT; };
84D017591527431F0008A4E0 /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = System/Library/Frameworks/CoreData.framework; sourceTree = SDKROOT; };
84D0175A1527431F0008A4E0 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
84D01775152744BD0008A4E0 /* OpenGL.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OpenGL.framework; path = System/Library/Frameworks/OpenGL.framework; sourceTree = SDKROOT; };
D31F324B1C11DEC100A77D54 /* tbbExample.ios.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = tbbExample.ios.app; sourceTree = BUILT_PRODUCTS_DIR; };
D31F32691C11DF1600A77D54 /* iOS.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; name = iOS.storyboard; path = ../iOS.storyboard; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
84D0174E1527431F0008A4E0 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
84D01776152744BD0008A4E0 /* OpenGL.framework in Frameworks */,
84D017561527431F0008A4E0 /* Cocoa.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
D31F32481C11DEC100A77D54 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
84B8DA6C152CA8D900D59B95 /* tbbExample */ = {
isa = PBXGroup;
children = (
84B8DAA4152CB05200D59B95 /* polymain.cpp */,
84B8DAA5152CB05200D59B95 /* polymain.h */,
84B8DAA6152CB05200D59B95 /* polyover.cpp */,
84B8DAA7152CB05200D59B95 /* polyover.h */,
84B8DAA8152CB05200D59B95 /* pover_global.h */,
84B8DAA9152CB05200D59B95 /* pover_video.cpp */,
84B8DAAA152CB05200D59B95 /* pover_video.h */,
84B8DAAB152CB05200D59B95 /* rpolygon.h */,
84B8DA98152CAD8600D59B95 /* Gui layer */,
84B8DA7B152CA97B00D59B95 /* Resources */,
);
name = tbbExample;
sourceTree = "<group>";
};
84B8DA7B152CA97B00D59B95 /* Resources */ = {
isa = PBXGroup;
children = (
D31F32691C11DF1600A77D54 /* iOS.storyboard */,
84B8DA7C152CA97B00D59B95 /* InfoPlist.strings */,
84B8DA7E152CA97B00D59B95 /* MainMenu.xib */,
);
name = Resources;
path = ../../../common/gui/xcode/tbbExample/en.lproj;
sourceTree = "<group>";
};
84B8DA98152CAD8600D59B95 /* Gui layer */ = {
isa = PBXGroup;
children = (
84B8DA99152CADF400D59B95 /* macvideo.cpp */,
84B8DA6F152CA90100D59B95 /* main.m */,
84B8DA70152CA90100D59B95 /* OpenGLView.h */,
84B8DA71152CA90100D59B95 /* OpenGLView.m */,
84B8DA72152CA90100D59B95 /* tbbAppDelegate.h */,
84B8DA73152CA90100D59B95 /* tbbAppDelegate.m */,
84B8DA75152CA90100D59B95 /* tbbExample-Prefix.pch */,
);
name = "Gui layer";
sourceTree = "<group>";
};
84D017461527431F0008A4E0 = {
isa = PBXGroup;
children = (
84B8DA6C152CA8D900D59B95 /* tbbExample */,
84D017541527431F0008A4E0 /* Frameworks */,
84D017521527431F0008A4E0 /* Products */,
);
sourceTree = "<group>";
};
84D017521527431F0008A4E0 /* Products */ = {
isa = PBXGroup;
children = (
84D017511527431F0008A4E0 /* tbbExample.app */,
D31F324B1C11DEC100A77D54 /* tbbExample.ios.app */,
);
name = Products;
sourceTree = "<group>";
};
84D017541527431F0008A4E0 /* Frameworks */ = {
isa = PBXGroup;
children = (
84D01775152744BD0008A4E0 /* OpenGL.framework */,
84D017551527431F0008A4E0 /* Cocoa.framework */,
84D017571527431F0008A4E0 /* Other Frameworks */,
);
name = Frameworks;
sourceTree = "<group>";
};
84D017571527431F0008A4E0 /* Other Frameworks */ = {
isa = PBXGroup;
children = (
84D017581527431F0008A4E0 /* AppKit.framework */,
84D017591527431F0008A4E0 /* CoreData.framework */,
84D0175A1527431F0008A4E0 /* Foundation.framework */,
);
name = "Other Frameworks";
sourceTree = "<group>";
};
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
84D017501527431F0008A4E0 /* tbbExample */ = {
isa = PBXNativeTarget;
buildConfigurationList = 84D01772152743200008A4E0 /* Build configuration list for PBXNativeTarget "tbbExample" */;
buildPhases = (
84D0174D1527431F0008A4E0 /* Sources */,
84D0174E1527431F0008A4E0 /* Frameworks */,
84D0174F1527431F0008A4E0 /* Resources */,
);
buildRules = (
C3C5897B2191EB8300DAC94C /* PBXBuildRule */,
);
dependencies = (
);
name = tbbExample;
productName = tbbExample;
productReference = 84D017511527431F0008A4E0 /* tbbExample.app */;
productType = "com.apple.product-type.application";
};
D31F324A1C11DEC100A77D54 /* tbbExample.ios */ = {
isa = PBXNativeTarget;
buildConfigurationList = D31F325F1C11DEC100A77D54 /* Build configuration list for PBXNativeTarget "tbbExample.ios" */;
buildPhases = (
D31F32471C11DEC100A77D54 /* Sources */,
D31F32481C11DEC100A77D54 /* Frameworks */,
D31F32491C11DEC100A77D54 /* Resources */,
);
buildRules = (
);
dependencies = (
);
name = tbbExample.ios;
productName = tbbExample.ios;
productReference = D31F324B1C11DEC100A77D54 /* tbbExample.ios.app */;
productType = "com.apple.product-type.application";
};
/* End PBXNativeTarget section */
/* Begin PBXProject section */
84D017481527431F0008A4E0 /* Project object */ = {
isa = PBXProject;
attributes = {
CLASSPREFIX = tbb;
LastUpgradeCheck = 1000;
TargetAttributes = {
D31F324A1C11DEC100A77D54 = {
CreatedOnToolsVersion = 7.1.1;
DevelopmentTeam = 7J8M3RM94C;
};
};
};
buildConfigurationList = 84D0174B1527431F0008A4E0 /* Build configuration list for PBXProject "polygon_overlay" */;
compatibilityVersion = "Xcode 3.2";
developmentRegion = English;
hasScannedForEncodings = 0;
knownRegions = (
en,
Base,
);
mainGroup = 84D017461527431F0008A4E0;
productRefGroup = 84D017521527431F0008A4E0 /* Products */;
projectDirPath = "";
projectRoot = "";
targets = (
84D017501527431F0008A4E0 /* tbbExample */,
D31F324A1C11DEC100A77D54 /* tbbExample.ios */,
);
};
/* End PBXProject section */
/* Begin PBXResourcesBuildPhase section */
84D0174F1527431F0008A4E0 /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
84B8DA7A152CA90100D59B95 /* (null) in Resources */,
84B8DA80152CA97B00D59B95 /* InfoPlist.strings in Resources */,
84B8DA81152CA97B00D59B95 /* MainMenu.xib in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
D31F32491C11DEC100A77D54 /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
D31F326B1C11DF6000A77D54 /* iOS.storyboard in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXResourcesBuildPhase section */
/* Begin PBXSourcesBuildPhase section */
84D0174D1527431F0008A4E0 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
84B8DA77152CA90100D59B95 /* main.m in Sources */,
84B8DA78152CA90100D59B95 /* OpenGLView.m in Sources */,
84B8DA79152CA90100D59B95 /* tbbAppDelegate.m in Sources */,
84B8DA9A152CADF400D59B95 /* macvideo.cpp in Sources */,
84B8DAAC152CB05200D59B95 /* polymain.cpp in Sources */,
84B8DAAD152CB05200D59B95 /* polyover.cpp in Sources */,
84B8DAAE152CB05200D59B95 /* pover_video.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
D31F32471C11DEC100A77D54 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
D31F32641C11DEE700A77D54 /* pover_video.cpp in Sources */,
D31F32631C11DEE300A77D54 /* polyover.cpp in Sources */,
D31F32651C11DEEC00A77D54 /* macvideo.cpp in Sources */,
D31F32681C11DEF600A77D54 /* tbbAppDelegate.m in Sources */,
D31F32621C11DEE000A77D54 /* polymain.cpp in Sources */,
D31F32661C11DEF000A77D54 /* main.m in Sources */,
D31F32671C11DEF300A77D54 /* OpenGLView.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXSourcesBuildPhase section */
/* Begin PBXVariantGroup section */
84B8DA7C152CA97B00D59B95 /* InfoPlist.strings */ = {
isa = PBXVariantGroup;
children = (
84B8DA7D152CA97B00D59B95 /* en */,
);
name = InfoPlist.strings;
sourceTree = "<group>";
};
84B8DA7E152CA97B00D59B95 /* MainMenu.xib */ = {
isa = PBXVariantGroup;
children = (
84B8DA7F152CA97B00D59B95 /* en */,
);
name = MainMenu.xib;
sourceTree = "<group>";
};
/* End PBXVariantGroup section */
/* Begin XCBuildConfiguration section */
84D01770152743200008A4E0 /* Debug64 */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = YES;
CLANG_CXX_LANGUAGE_STANDARD = "c++11";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = c11;
GCC_DYNAMIC_NO_PIC = NO;
GCC_ENABLE_OBJC_EXCEPTIONS = YES;
GCC_NO_COMMON_BLOCKS = YES;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
"$(inherited)",
);
GCC_SYMBOLS_PRIVATE_EXTERN = NO;
GCC_VERSION = "";
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
HEADER_SEARCH_PATHS = (
"$(TBBROOT)/include",
/opt/intel/tbb/include,
);
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = "$(TBBROOT)/lib /opt/intel/tbb/lib";
LIBRARY_SEARCH_PATHS = (
"$(TBBROOT)/lib",
/opt/intel/tbb/lib,
);
MACOSX_DEPLOYMENT_TARGET = 10.11;
ONLY_ACTIVE_ARCH = YES;
OTHER_LDFLAGS = (
"-m64",
"-ltbb_debug",
"-ltbbmalloc_debug",
);
SDKROOT = macosx;
VALID_ARCHS = x86_64;
};
name = Debug64;
};
84D01771152743200008A4E0 /* Release64 */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = YES;
CLANG_CXX_LANGUAGE_STANDARD = "c++11";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = YES;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = c11;
GCC_ENABLE_OBJC_EXCEPTIONS = YES;
GCC_NO_COMMON_BLOCKS = YES;
GCC_VERSION = "";
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
HEADER_SEARCH_PATHS = (
"$(TBBROOT)/include",
/opt/intel/tbb/include,
);
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = "$(TBBROOT)/lib /opt/intel/tbb/lib";
LIBRARY_SEARCH_PATHS = (
"$(TBBROOT)/lib",
/opt/intel/tbb/lib,
);
MACOSX_DEPLOYMENT_TARGET = 10.11;
OTHER_LDFLAGS = (
"-m64",
"-ltbb",
"-ltbbmalloc",
);
SDKROOT = macosx;
VALID_ARCHS = x86_64;
};
name = Release64;
};
84D01773152743200008A4E0 /* Debug64 */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_OBJC_ARC = NO;
COMBINE_HIDPI_IMAGES = YES;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "../../../common/gui/xcode/tbbExample/tbbExample-Prefix.pch";
HEADER_SEARCH_PATHS = "$(inherited)";
ICC_CXX_LANG_DIALECT = "c++11";
ICC_TBB = YES;
INFOPLIST_FILE = "../../../common/gui/xcode/tbbExample/tbbExample-Info.plist";
LIBRARY_SEARCH_PATHS = "$(inherited)";
MACOSX_DEPLOYMENT_TARGET = 10.11;
PRODUCT_NAME = "$(TARGET_NAME)";
RUN_CLANG_STATIC_ANALYZER = YES;
VERSION_INFO_BUILDER = "$(TARGET_NAME)";
WRAPPER_EXTENSION = app;
};
name = Debug64;
};
84D01774152743200008A4E0 /* Release64 */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_OBJC_ARC = NO;
COMBINE_HIDPI_IMAGES = YES;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "../../../common/gui/xcode/tbbExample/tbbExample-Prefix.pch";
HEADER_SEARCH_PATHS = "$(inherited)";
ICC_CXX_LANG_DIALECT = "c++11";
ICC_TBB = YES;
INFOPLIST_FILE = "../../../common/gui/xcode/tbbExample/tbbExample-Info.plist";
LIBRARY_SEARCH_PATHS = "$(inherited)";
MACOSX_DEPLOYMENT_TARGET = 10.11;
PRODUCT_NAME = "$(TARGET_NAME)";
RUN_CLANG_STATIC_ANALYZER = YES;
VERSION_INFO_BUILDER = "$(TARGET_NAME)";
WRAPPER_EXTENSION = app;
};
name = Release64;
};
D31F32601C11DEC100A77D54 /* Debug64 */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
DEBUG_INFORMATION_FORMAT = dwarf;
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
"$(inherited)",
"__TBB_IOS=1",
);
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
HEADER_SEARCH_PATHS = "\"$(SRCROOT)/../../../../include\"";
INFOPLIST_FILE = "../../../common/gui/xcode/tbbExample/tbbExample-Info.ios.plist";
IPHONEOS_DEPLOYMENT_TARGET = 9.1;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path";
LIBRARY_SEARCH_PATHS = "\"$(SRCROOT)/../../../../lib/ios\"";
MTL_ENABLE_DEBUG_INFO = YES;
PRODUCT_BUNDLE_IDENTIFIER = com.tbb.example;
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = iphoneos;
TARGETED_DEVICE_FAMILY = 1;
};
name = Debug64;
};
D31F32611C11DEC100A77D54 /* Release64 */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = NO;
ENABLE_NS_ASSERTIONS = NO;
GCC_PREPROCESSOR_DEFINITIONS = "__TBB_IOS=1";
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
HEADER_SEARCH_PATHS = "\"$(SRCROOT)/../../../../include\"";
INFOPLIST_FILE = "../../../common/gui/xcode/tbbExample/tbbExample-Info.ios.plist";
IPHONEOS_DEPLOYMENT_TARGET = 9.1;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path";
LIBRARY_SEARCH_PATHS = "\"$(SRCROOT)/../../../../lib/ios\"";
MTL_ENABLE_DEBUG_INFO = NO;
PRODUCT_BUNDLE_IDENTIFIER = com.tbb.example;
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = iphoneos;
TARGETED_DEVICE_FAMILY = 1;
VALIDATE_PRODUCT = YES;
};
name = Release64;
};
/* End XCBuildConfiguration section */
/* Begin XCConfigurationList section */
84D0174B1527431F0008A4E0 /* Build configuration list for PBXProject "polygon_overlay" */ = {
isa = XCConfigurationList;
buildConfigurations = (
84D01770152743200008A4E0 /* Debug64 */,
84D01771152743200008A4E0 /* Release64 */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release64;
};
84D01772152743200008A4E0 /* Build configuration list for PBXNativeTarget "tbbExample" */ = {
isa = XCConfigurationList;
buildConfigurations = (
84D01773152743200008A4E0 /* Debug64 */,
84D01774152743200008A4E0 /* Release64 */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release64;
};
D31F325F1C11DEC100A77D54 /* Build configuration list for PBXNativeTarget "tbbExample.ios" */ = {
isa = XCConfigurationList;
buildConfigurations = (
D31F32601C11DEC100A77D54 /* Debug64 */,
D31F32611C11DEC100A77D54 /* Release64 */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release64;
};
/* End XCConfigurationList section */
};
rootObject = 84D017481527431F0008A4E0 /* Project object */;
}

View File

@@ -0,0 +1,91 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0710"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "D31F324A1C11DEC100A77D54"
BuildableName = "tbbExample.ios.app"
BlueprintName = "tbbExample.ios"
ReferencedContainer = "container:polygon_overlay.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "D31F324A1C11DEC100A77D54"
BuildableName = "tbbExample.ios.app"
BlueprintName = "tbbExample.ios"
ReferencedContainer = "container:polygon_overlay.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "D31F324A1C11DEC100A77D54"
BuildableName = "tbbExample.ios.app"
BlueprintName = "tbbExample.ios"
ReferencedContainer = "container:polygon_overlay.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "D31F324A1C11DEC100A77D54"
BuildableName = "tbbExample.ios.app"
BlueprintName = "tbbExample.ios"
ReferencedContainer = "container:polygon_overlay.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>

View File

@@ -0,0 +1,99 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0710"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "84D017501527431F0008A4E0"
BuildableName = "tbbExample.app"
BlueprintName = "tbbExample"
ReferencedContainer = "container:tbbExample.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "84D017501527431F0008A4E0"
BuildableName = "tbbExample.app"
BlueprintName = "tbbExample"
ReferencedContainer = "container:polygon_overlay.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
customWorkingDirectory = "/tmp"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "NO"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "84D017501527431F0008A4E0"
BuildableName = "tbbExample.app"
BlueprintName = "tbbExample"
ReferencedContainer = "container:polygon_overlay.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<EnvironmentVariables>
<EnvironmentVariable
key = "DYLD_LIBRARY_PATH"
value = "$(SRCROOT)/../../../../lib"
isEnabled = "YES">
</EnvironmentVariable>
</EnvironmentVariables>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "84D017501527431F0008A4E0"
BuildableName = "tbbExample.app"
BlueprintName = "tbbExample"
ReferencedContainer = "container:tbbExample.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>

View File

@@ -0,0 +1,63 @@
# Copyright (c) 2005-2020 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Common Makefile that builds and runs example.
# Just specify your program basename
PROG=Seismic
ARGS=auto 0
PERF_RUN_ARGS=auto 10000 silent
LIGHT_ARGS=1:2 100
# Trying to find if icl.exe is set
CXX1 = $(TBB_CXX)-
CXX2 = $(CXX1:icl.exe-=icl.exe)
CXX = $(CXX2:-=cl.exe)
# Uncomment one of next lines to choose user interface type (console, gdiplus, direct draw)
#UI = con
UI = gdi
#UI = dd
# Machine architecture, auto-detected from TBB_TARGET_ARCH by default
# Use XARCH variable to change it. See index.html for more information
ARCH0 = $(TBB_TARGET_ARCH)-
ARCH1 = $(ARCH0:ia32-=x86)
ARCH2 = $(ARCH1:intel64-=AMD64)
XARCH = $(ARCH2:-=x86)
MAKEINC = ../../common/gui/Makefile.win
SOURCES = seismic_video.cpp universe.cpp main.cpp
all: release test
release: compiler_check
@$(MAKE) -f $(MAKEINC) UI=$(UI) CXX="$(CXX)" CXXFLAGS="$(CXXFLAGS)" LFLAGS="$(LDFLAGS) tbb.lib $(LIBS)" XARCH=$(XARCH) RCNAME=SeismicSimulation SOURCE="$(SOURCES)" EXE=$(PROG).exe build_one
debug: compiler_check
@$(MAKE) -f $(MAKEINC) UI=$(UI) DEBUG=_debug CXX="$(CXX)" CXXFLAGS="$(CXXFLAGS) /D TBB_USE_DEBUG" LFLAGS="$(LDFLAGS) tbb_debug.lib $(LIBS)" XARCH=$(XARCH) RCNAME=SeismicSimulation SOURCE="$(SOURCES)" EXE=$(PROG).exe build_one
clean:
@cmd.exe /C del $(PROG).exe *.obj *.?db *.manifest msvs\SeismicSimulation.res >nul 2>&1
test:
$(PROG) $(ARGS)
perf_build: compiler_check
@$(MAKE) -f $(MAKEINC) UI=con CXX="$(CXX)" CXXFLAGS="$(CXXFLAGS)" LFLAGS="$(LDFLAGS) tbb.lib $(LIBS)" XARCH=$(XARCH) RCNAME=SeismicSimulation SOURCE="$(SOURCES) " EXE=$(PROG).exe build_one
perf_run:
$(PROG) $(PERF_RUN_ARGS)
light_test:
$(PROG) $(LIGHT_ARGS)
compiler_check:
@echo compiler_test>compiler_test && @$(CXX) /E compiler_test >nul 2>&1 || echo "$(CXX) command not found. Check if CXX=$(CXX) is set properly"
@cmd.exe /C del compiler_test

View File

@@ -0,0 +1,134 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#define VIDEO_WINMAIN_ARGS
#include <iostream>
#include "tbb/tick_count.h"
#include "tbb/global_control.h"
#include "../../common/utility/utility.h"
#include "../../common/utility/get_default_num_threads.h"
#include "seismic_video.h"
#include "universe.h"
Universe u;
struct RunOptions {
//! It is used for console mode for test with different number of threads and also has
//! meaning for GUI: threads.first - use separate event/updating loop thread (>0) or not (0).
//! threads.second - initialization value for scheduler
utility::thread_number_range threads;
int numberOfFrames;
bool silent;
bool parallel;
RunOptions(utility::thread_number_range threads_ , int number_of_frames_ , bool silent_ , bool parallel_ )
: threads(threads_),numberOfFrames(number_of_frames_), silent(silent_), parallel(parallel_)
{
}
};
RunOptions ParseCommandLine(int argc, char *argv[]){
// zero number of threads means to run serial version
utility::thread_number_range threads(utility::get_default_num_threads,0,utility::get_default_num_threads());
int numberOfFrames = 0;
bool silent = false;
bool serial = false;
utility::parse_cli_arguments(argc,argv,
utility::cli_argument_pack()
//"-h" option for displaying help is present implicitly
.positional_arg(threads,"n-of-threads",utility::thread_number_range_desc)
.positional_arg(numberOfFrames,"n-of-frames","number of frames the example processes internally (0 means unlimited)")
.arg(silent,"silent","no output except elapsed time")
.arg(serial,"serial","in GUI mode start with serial version of algorithm")
);
return RunOptions(threads,numberOfFrames,silent,!serial);
}
int main(int argc, char *argv[])
{
try{
tbb::tick_count mainStartTime = tbb::tick_count::now();
RunOptions options = ParseCommandLine(argc,argv);
SeismicVideo video(u,options.numberOfFrames,options.threads.last,options.parallel);
// video layer init
if(video.init_window(u.UniverseWidth, u.UniverseHeight)) {
video.calc_fps = true;
video.threaded = options.threads.first > 0;
// video is ok, init Universe
u.InitializeUniverse(video);
// main loop
video.main_loop();
}
else if(video.init_console()) {
// do console mode
if (options.numberOfFrames == 0) {
options.numberOfFrames = 1000;
std::cout << "Substituting 1000 for unlimited frames because not running interactively\n";
}
for(int p = options.threads.first; p <= options.threads.last; p = options.threads.step(p)) {
tbb::tick_count xwayParallelismStartTime = tbb::tick_count::now();
u.InitializeUniverse(video);
int numberOfFrames = options.numberOfFrames;
#if __TBB_MIC_OFFLOAD
drawing_memory dmem = video.get_drawing_memory();
char *pMem = dmem.get_address();
size_t memSize = dmem.get_size();
#pragma offload target(mic) in(u, numberOfFrames, p, dmem), out(pMem:length(memSize))
{
// It is necessary to update the pointer on mic
// since the address spaces on host and on target are different
dmem.set_address(pMem);
u.SetDrawingMemory(dmem);
#endif // __TBB_MIC_OFFLOAD
if (p==0) {
//run a serial version
for( int i=0; i<numberOfFrames; ++i ) {
u.SerialUpdateUniverse();
}
} else {
tbb::global_control c(tbb::global_control::max_allowed_parallelism, p);
for( int i=0; i<numberOfFrames; ++i ) {
u.ParallelUpdateUniverse();
}
}
#if __TBB_MIC_OFFLOAD
}
#endif // __TBB_MIC_OFFLOAD
if (!options.silent){
double fps = options.numberOfFrames/((tbb::tick_count::now()-xwayParallelismStartTime).seconds());
std::cout<<fps<<" frame per sec with ";
if (p==0){
std::cout<<"serial code\n";
}else{
std::cout<<p<<" way parallelism\n";
}
}
}
}
video.terminate();
utility::report_elapsed_time((tbb::tick_count::now() - mainStartTime).seconds());
return 0;
}catch(std::exception& e){
std::cerr<<"error occurred. error text is :\"" <<e.what()<<"\"\n";
return 1;
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

View File

@@ -0,0 +1,145 @@
// Microsoft Visual C++ generated resource script.
//
#include "resource.h"
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#define APSTUDIO_HIDDEN_SYMBOLS
#include "windows.h"
#undef APSTUDIO_HIDDEN_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// English (U.S.) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
#ifdef _WIN32
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)
#endif //_WIN32
/////////////////////////////////////////////////////////////////////////////
//
// Icon
//
// Icon with lowest ID value placed first to ensure application icon
// remains consistent on all systems.
IDI_SEISMICSIMULATION ICON "SeismicSimulation.ico"
IDI_SMALL ICON "small.ico"
/////////////////////////////////////////////////////////////////////////////
//
// Menu
//
IDC_SEISMICSIMULATION MENU
BEGIN
POPUP "&File"
BEGIN
MENUITEM "&Parallel", ID_FILE_PARALLEL
MENUITEM "&Serial", ID_FILE_SERIAL
MENUITEM SEPARATOR
MENUITEM "&Enable GUI", ID_FILE_ENABLEGUI
MENUITEM "&Disable GUI", ID_FILE_DISABLEGUI
MENUITEM SEPARATOR
MENUITEM "E&xit", IDM_EXIT
END
POPUP "&Help"
BEGIN
MENUITEM "&About ...", IDM_ABOUT
END
END
/////////////////////////////////////////////////////////////////////////////
//
// Accelerator
//
IDC_SEISMICSIMULATION ACCELERATORS
BEGIN
VK_OEM_2, IDM_ABOUT, VIRTKEY, ALT, NOINVERT
"P", ID_FILE_PARALLEL, VIRTKEY, ALT, NOINVERT
"S", ID_FILE_SERIAL, VIRTKEY, ALT, NOINVERT
"D", ID_FILE_DISABLEGUI, VIRTKEY, ALT, NOINVERT
"E", ID_FILE_ENABLEGUI, VIRTKEY, ALT, NOINVERT
END
/////////////////////////////////////////////////////////////////////////////
//
// Dialog
//
IDD_ABOUTBOX DIALOG 22, 17, 230, 75
STYLE DS_SETFONT | DS_MODALFRAME | WS_CAPTION | WS_SYSMENU
CAPTION "About"
FONT 8, "System"
BEGIN
ICON IDI_SEISMICSIMULATION,IDC_MYICON,14,9,16,16
LTEXT "SeismicSimulation Version 1.1",IDC_STATIC,49,10,119,8,SS_NOPREFIX
LTEXT "Copyright (C) 2005-2008",IDC_STATIC,49,20,119,8
DEFPUSHBUTTON "OK",IDOK,195,6,30,11,WS_GROUP
END
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE
BEGIN
"resource.h\0"
END
2 TEXTINCLUDE
BEGIN
"#define APSTUDIO_HIDDEN_SYMBOLS\r\n"
"#include ""windows.h""\r\n"
"#undef APSTUDIO_HIDDEN_SYMBOLS\r\n"
"\0"
END
3 TEXTINCLUDE
BEGIN
"\r\n"
"\0"
END
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// String Table
//
STRINGTABLE
BEGIN
IDS_APP_TITLE "SeismicSimulation"
IDC_SEISMICSIMULATION "SEISMICSIMULATION"
END
#endif // English (U.S.) resources
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED

View File

@@ -0,0 +1,48 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by SeismicSimulation.rc
//
#define IDC_MYICON 2
#define IDD_SEISMICSIMULATION_DIALOG 102
#define IDS_APP_TITLE 103
#define IDD_ABOUTBOX 103
#define IDM_ABOUT 104
#define IDM_EXIT 105
#define IDI_SEISMICSIMULATION 107
#define IDI_SMALL 108
#define IDC_SEISMICSIMULATION 109
#define IDR_MAINFRAME 128
#define ID_FILE_PARALLEL 32771
#define ID_FILE_SERIAL 32772
#define IDM_PARALLEL 32773
#define ID_FILE_ENABLEGUI 32774
#define ID_FILE_DISABLEGUI 32775
#define IDC_STATIC -1
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NO_MFC 1
#define _APS_NEXT_RESOURCE_VALUE 129
#define _APS_NEXT_COMMAND_VALUE 32782
#define _APS_NEXT_CONTROL_VALUE 1000
#define _APS_NEXT_SYMED_VALUE 110
#endif
#endif

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

View File

@@ -0,0 +1,471 @@
<!DOCTYPE html>
<html xmlns:mso="urn:schemas-microsoft-com:office:office" xmlns:msdt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882">
<head>
<meta charset="UTF-8">
<style>
::selection {
background: #b7ffb7;
}
::-moz-selection {
background: #b7ffb7;
}
body {
font-family: Arial, Helvetica, sans-serif;
font-size: 16px;
width: 800px;
margin: 0 auto;
}
#banner {
/* Div for banner */
float:left;
margin: 0px;
margin-bottom: 10px;
width: 100%;
background-color: #0071C5;
z-index: 0;
}
#banner .logo {
/* Apply to logo in banner. Add as class to image tag. */
float: left;
margin-right: 20px;
margin-left: 20px;
margin-top: 15px;
padding-bottom: 5px;
}
h1 {
text-align: center;
font-size: 36px;
}
h1.title {
/* Add as class to H1 in banner */
font-family: "Intel Clear", Verdana, Arial, sans-serif;
font-weight:normal;
color: #FFFFFF;
font-size: 170%;
margin-right: 40px;
margin-left: 40px;
padding-right: 20px;
text-indent: 20px;
}
.h3-alike {
display:inline;
font-size: 1.17em;
font-weight: bold;
color: #0071C5;
}
h3 {
font-size: 1.17em;
font-weight: bold;
color: #0071C5;
}
.h4-alike {
display:inline;
font-size: 1.05em;
font-weight: bold;
}
pre {
font-family: "Consolas", Monaco, monospace;
font-size:small;
background: #fafafa;
margin: 0;
padding-left:20px;
}
#footer {
font-size: small;
}
code {
font-family: "Consolas", Monaco, monospace;
}
.code-block
{
padding-left:20px;
}
.changes {
margin: 1em 0;
}
.changes input:active {
position: relative;
top: 1px;
}
.changes input:hover:after {
padding-left: 16px;
font-size: 10px;
content: 'More';
}
.changes input:checked:hover:after {
content: 'Less';
}
.changes input + .show-hide {
display: none;
}
.changes input:checked + .show-hide {
display: block;
}
ul {
margin: 0;
padding: 0.5em 0 0.5em 2.5em;
}
ul li {
margin-bottom: 3px;
}
ul li:last-child {
margin-bottom: 0;
}
.disc {
list-style-type:disc
}
.circ {
list-style-type:circle
}
.single {
padding: 0 0.5em;
}
/* ------------------------------------------------- */
/* Table styles */
table{
margin-bottom:5pt;
border-collapse:collapse;
margin-left:0px;
margin-top:0.3em;
font-size:10pt;
}
tr{
vertical-align:top;
}
th,
th h3{
padding:4px;
text-align:left;
background-color:#0071C5;
font-weight:bold;
margin-top:1px;
margin-bottom:0;
color:#FFFFFF;
font-size:10pt;
vertical-align:middle;
}
th{
border:1px #dddddd solid;
padding-top:2px;
padding-bottom:0px;
padding-right:3px;
padding-left:3px;
}
td{
border:1px #dddddd solid;
vertical-align:top;
font-size:100%;
text-align:left;
margin-bottom:0;
}
td,
td p{
margin-top:0;
margin-left:0;
text-align:left;
font-size:inherit;
line-height:120%;
}
td p{
margin-bottom:0;
padding-top:5px;
padding-bottom:5px;
padding-right:5px;
padding-left:1px;
}
.noborder{
border:0px none;
}
.noborder1stcol{
border:0px none;
padding-left:0pt;
}
td ol{
font-size:inherit;
margin-left:28px;
}
td ul{
font-size:inherit;
margin-left:24px;
}
.DefListTbl{
width:90%;
margin-left:-3pt;
}
.syntaxdiagramtbl{
margin-left:-3pt;
}
.sdtbl{
}
.sdrow{
}
.sdtblp{
border:0px none;
font-size:inherit;
line-height:120%;
margin-bottom:0;
padding-bottom:0px;
padding-top:5px;
padding-left:0px;
padding-right:5px;
vertical-align:top;
}
.idepara, .ide_para{
border:0px none;
font-size:inherit;
line-height:120%;
margin-bottom:0;
padding-bottom:0px;
padding-top:5px;
padding-left:0px;
padding-right:5px;
vertical-align:top;
}
.specs {
border-collapse:collapse;
}
.specs td, .specs th {
font-size: 14px;
}
.specs td {
border: 1px solid black;
}
.specs td td, .specs td th {
border: none;
}
.specs td, .specs td td, .specs td th {
padding: 0 0.2em 0.2em;
text-align: center;
}
.specs td tr:last-child td,
.specs td tr:last-child th {
padding: 0 0.2em;
}
.serial-time {
}
.modified-time {
width: 6.5em;
}
.compiler {
}
.comp-opt {
}
.sys-specs {
width: 18em;
}
.note {
font-size:small;
font-style: italic;
}
</style>
<title>Intel&reg; Threading Building Blocks. Seismic sample</title>
</head>
<body>
<div id="banner">
<img class="logo" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEMAAAAsCAYAAAA+aAX8AAAAAXNSR0IArs4c6QAAAARnQU1BAACx
jwv8YQUAAAAJcEhZcwAALiIAAC4iAari3ZIAAAAZdEVYdFNvZnR3YXJlAEFkb2JlIEltYWdlUmVh
ZHlxyWU8AAAIN0lEQVRoQ+WaCaxdUxSGW2ouatZWaVS15nkqkZhSVERQglLEPCam1BCixhqqCKUS
NIiYpxhqHmouIeaY5ylFzA/v1fev8+/j3N5737v3vtf3buNP/uy9/7X2Ovuse4a997m9mgltbW2L
wRHwcHgFfAx+AH+GCb/BT2fNmvUk5ZXwYOrrOsTcCU5CJ74pPBJeA5+Bn8LfOLmagf/f8Af4NrwD
ngg3wdTHh2pOMMB1Gejx8AE4M85mNqD/A7+D78GXkXQFTIMPwUfhdPg6/AxWTRw29b8QruPD9zwY
zPrwHPi2xxmg3QrfgDfD05BGU24EB1HvC3s7REXgtwDsDzeEY+Ak+AJsUfwE2sJdcBN37V4whiU4
+KGUM2JEBtpzUInZEa5g9y4FcYfAo+GLPmwOND2HFrXrnAUHWgnq0vzDB2+Bt0H9coPs1m3gmNvD
ZyITBu234Jp26XoQfCC80sfTAXVv7wOXskuPgnHoSvnTw9P49MDdyOauAQEXhWdC4Vd4ARxmc1OB
cW0Gv3U+lJDvKFa0ufMg4GXwR3gs7J57sRNoaWnR2+znLB2RkKds6jwItvbckIQiGO+eTkSby71t
qh100qtsUCJxmmpSw5i2gWebR1jWm2047T1gf0vyfViJEKi/TtHua7wMdNJs8U/zDzjUpqYA47k4
O704wY+kUZ2P+glQc5ldac9j323sF1cH2EB6h8BxYZdbRDeDOJ16UBJiHDFuMMdYbhjEGA8DxJ4h
jXIemmMpz6ccqbZ1JUlT/3SrHC+9XeB0MjzV9RHqKFAXVg2nBkH/lxxO8aZYbhjEKEuGQH1BuCKc
z1IAN61jAtiut1wZ+ByIkwa6r9t6ZmhSFZw9eL0gxiMw4SLLDYMYFZNRDbhpcpgwzXI5MOqSEvKM
Ue8D+xU4r/Xe+C8HB1ThkhFgNqAXk6FVqyZuA1LcItBXQd+WUvf6YMslwFZvMs7KvMP/SculwKa3
hfYPPsZpfsvS9QD9PRHbcOmUC9J+H2qfoRJ/0MHgFhHIQC8mQ8twxZ0Ji099vSGegn/TP0BdD/Db
Ycn0nna9yZiceQcetFwKDE/4oNtZCtDeXHoC7dWlU1Uyvs7U6sBHJ7FaBAPU82TYJUAzFnCU+1mq
COyfwGLi6k3G05l34BrL/wFxjA/0mKUcaNqBKiJODHclQ3sLCVqZprfEvVCLtThhiskRDFAvXhnv
QPlfi5uW7ytTL14Nr0Bd1pfDXy1Lv93h6koGLstCLR/SuPJ5SQBBD8hPZATbWs6BrdZk7B4dDNpT
Mjkw3bL0YjLOsxygPUWDyExtD1GNV6JAeyTUBlDCKtbrScYxhfjyj1s+B9o+dnifIj94AnpNyaC9
f3QwkNJCTnjOsvRiMi6xrHiaA3ycyYFNbcqBpisl/aoHWaspGdg03uIc43mb/gOilt3CREslQG80
GedmlkC1KyNPBnU9wOPWMp6Aut0S74HfwIQJ7ldTMjBPdBIiGWC0TRkQlseWNmR2tlwC9DmZjEmW
pQ/zOAKqtwdcrnW/DpOBPtp9Ii6F9lhL1yWIo2zUvVhxzYHeLVcG/QfT/iuTA3qwan+zGndVP8p2
k4G8E/wLW4D6PxTlnxgwaDEjaMe6n+USYOvqZKTbUrjQcor3ZSYHRtjULvCrmgwkfY5oRc9B+3Cb
S4FhIhS+gAtZLgH9Y6GWuQU6mwx9IEqYajlA+47CsZ6lGovFBDTNkA9xM4CmpXsAWySDUrPjqZQl
QBsfnSoB41UKAvS9ouJmDfpaDpTQ2WRcXYinCZm+pdyEtDClPgLloP0unABPp3lrpoZ+KkWskSgP
sVZMhlat2t7LQftE2aoCh0sVBOheXclyCYjTp7W19bUsZAQtJuPLTA39gOhg0D7PJtny1xj1tWA+
sUpAG2j7mZaqAh9tzPSVP+XStL+w/qY1XRlfWdOSYXvp7QKnU6Ayqk4jLZcB2zD4gv1iu52qkvG5
NKPsyrCuPs9aDtDeDr4EtS7RRyXNCgfYLPtYfoC33D0Hul6tE6jOfvsMhVqaT8PWG85PXR+WxlOP
pHUIHPNXDsif7NWAT773STdlX6vK4ebi4WRgWybZqFe86tBXUAw4BL+S7UTautTXo9yFcjdKPbsq
PuQTsKdbZ16YLzZrAgdRRvXLCF/Big/R/wXInn5dffdMt8opNs214Bz6cyqNbUDRcZwTIWjDt3m+
XtcBxq3pvL6p6mFftlFUE+i8JPxRCRGoawVbcVepGcF4V4eTGPNPHv+7NjUGAhzmQOl20fyhphlg
T4CxLcQw9WC9Gxb3P4Q37NY4CHJXCuhSW3JnwEXs0qNgSHqVbw210ZP2XwK0A65/6C6NgziaAU5X
wCIUHB4H86227gKH1+JtL3gd1N5sCdACbgZo5rtgnQKx+hLs/ixsdjBXBd2TtyKNhUOp1/dprgMQ
rx9x16fcn1KbttrIyf9OkICWw1KApvY2YyXbpSBobKf7OGXApFtI+5d3Qq1BDoL6V87GcDVc9Ivq
E4D+bjTQbc1i9demreDu8Ch0ffG6hdnmDMrvFbsSsAXczIGk3fwb4VYe+pwBB9Angkd83ADtqgkq
AjetdTTV1icDlfl+Qi3AP4elHEjaDXscHgFjPdNt4ID6S9B9sNLiKoelmuFuJbCpDJi+hvqz2qFw
iIfWc2AQusxPgvq484vH2eUgtpYHH0Hteeqb75ZwMQ+j+cDg9PlwFDwd6o9sr0KtbWI/tSPgp32M
76H+s6mNX3030df5neGq1OtbZDUbOIlFoFaha0L9j0qfCHeAerDqVtODU8+hNThZfR1fHHbpG6kx
9Or1LzUmVVz+HJXDAAAAAElFTkSuQmCC">
<h1 class="title">Intel&reg; Threading Building Blocks.<br>Seismic sample</h1>
</div>
<p>
Parallel seismic wave simulation that demonstrates use of parallel_for and affinity_partitioner.
<br><br>
The example can be built in the offload version to run on Intel&reg; Many Integrated Core (Intel&reg; MIC) Architecture based coprocessor (see <a href="../../index.html">build instructions</a>).
<br><br>
<b>Note:</b> Currently, the offload version does not support GUI and can only be used with console mode.
</p>
<div class="changes">
<div class="h3-alike">System Requirements</div>
<input type="checkbox">
<div class="show-hide">
<p>
For the most up to date system requirements, see the <a href="http://software.intel.com/en-us/articles/intel-threading-building-blocks-release-notes">release notes.</a>
</p>
</div>
</div>
<div class="changes">
<div class="h3-alike">Files</div>
<input type="checkbox" checked="checked">
<div class="show-hide">
<dl>
<dt><a href="main.cpp">main.cpp</a>
<dd>Main program which parses command line options and runs the algorithm with different numbers of threads.
<dt><a href="universe.h">universe.h</a>
<dd>Wave propagation methods interface.
<dt><a href="universe.cpp">universe.cpp</a>
<dd>Wave propagation methods implementation.
<dt><a href="seismic_video.h">seismic_video.h</a>
<dd>GUI mode support interface.
<dt><a href="seismic_video.cpp">seismic_video.cpp</a>
<dd>GUI mode support implementation.
<dt><a href="Makefile">Makefile</a>
<dd>Makefile for building the example.
</dl>
</div>
</div>
<div class="changes">
<div class="h3-alike">Directories</div>
<input type="checkbox" checked="checked">
<div class="show-hide">
<dl>
<dt><a href="msvs/">msvs</a>
<dd>Contains Microsoft* Visual Studio* workspace for building and running the example (Windows* systems only).
<dt><a href="xcode/">xcode</a>
<dd>Contains Xcode* IDE workspace for building and running the example (macOS* systems only).
</dl>
<p>For information about the minimum supported version of IDE, see <a href="http://software.intel.com/en-us/articles/intel-threading-building-blocks-release-notes">release notes.</a></p>
</div>
</div>
<div class="changes">
<div class="h3-alike">Build instructions</div>
<input type="checkbox" checked="checked">
<div class="show-hide">
<p>General build directions can be found <a href="../../index.html">here</a>.</p>
<p>The following additional options are supported:</p>
<dl>
<dt><tt>make [(general targets: {release, debug} [test])] UI={con, gdi, d2d, x, mac}</tt>
<dd>Build and run as usual, but build with the specified GUI driver: console, GDI+*,
Direct2D*, X11, or OpenGL*
(see the description of the <a href="../../common/index.html">common GUI code</a>
for more information on available graphics support).<br>
For Linux* and macOS* systems, the best available driver is detected automatically by the Makefile.<br>
For Windows* systems, UI=gdi is the default GUI driver; compiling with UI=d2d may offer superior
performance, but can only be used if the Microsoft* DirectX* SDK is installed on your system
and if overlay is supported by your graphics card.<br>
Use UI=con to build without the GUI for use in making performance measurements
<i>(strongly recommended when measuring performance or scalability; see note below)</i>.
<dt><tt>make [(above options or targets)] XARCH=x64</tt>
<dd>Build and run as above, but also specify XARCH=x64
(or XARCH=AMD64 for older compilers) when building the example on Windows* as a 64-bit binary.
<dt><tt>make [(above options or targets)] DDLIB_DIR=&lt;<i>specify path to Direct Draw* SDK here</i>&gt;</tt>
<dd>If you experience ddraw.lib linking problems, specify the correct library directory via this option.
<dt><tt>make [(above options or targets)] CXXFLAGS=-DX_FULLSYNC</tt>
<dd>Build and run as above, but enable full X11 synchronization if you experience "tearing" of motion on slower video systems.
</dl>
</div>
</div>
<div class="changes">
<div class="h3-alike">Usage</div>
<input type="checkbox" checked="checked">
<div class="show-hide">
<dl>
<dt><tt>seismic <i>-h</i></tt>
<dd>Prints the help for command line options
<dt><tt>seismic [<i>n-of-threads</i>=value] [<i>n-of-frames</i>=value] [<i>silent</i>] [<i>serial</i>]</tt>
<dt><tt>seismic [<i>n-of-threads</i> [<i>n-of-frames</i>]] [<i>silent</i>] [<i>serial</i>]</tt>
<dd><i>n-of-threads</i> is the number of threads to use; a range of the form low[:high], where low and optional high are non-negative integers or 'auto' for a platform-specific default number.<br>
<i>n-of-frames</i> is a number of frames the example processes internally.<br>
<i>silent</i> - no output except elapsed time.<br>
<i>serial</i> - in GUI mode start with serial version of algorithm.<br>
<dt>To run a short version of this example, e.g., for use with Intel&reg; Parallel Inspector::
<dd>Build a <i>debug</i> version of the example
(see the <a href="../../index.html">build instructions</a>).
<br>Run it with the desired number of threads and smaller number of frames, e.g., <tt>seismic 4 5</tt>.
</dl>
</div>
</div>
<div class="changes">
<div class="h3-alike">Hot keys</div>
<input type="checkbox" checked="checked">
<div class="show-hide">
<p>
The following hot keys can be used in interactive execution mode when the example is compiled with the graphical
user interface:
</p>
<dl>
<dt>&lt;left mouse button&gt;
<dd>Starts new seismic wave in place specified by mouse cursor.
<dt>&lt;space&gt;
<dd>Toggles between parallel and serial execution modes.
<dt>&lt;p&gt;
<dd>Enables parallel execution mode.
<dt>&lt;s&gt;
<dd>Enables serial execution mode.
<dt>&lt;e&gt;
<dd>Enables screen updates.
<dt>&lt;d&gt;
<dd>Disables screen updates <i>(strongly recommended when measuring performance or scalability; see note below)</i>.
<dt>&lt;esc&gt;
<dd>Stops execution.
</dl>
</div>
</div>
<div class="changes">
<div class="h3-alike">Notes</div>
<input type="checkbox" checked="checked">
<div class="show-hide">
<ul>
<li>While running with the GUI display turned on should yield reasonable performance in most cases, <i>running with the GUI
display turned off is strongly recommended</i> in order to demonstrate the full performance and scalability of the example.
</ul>
</div>
</div>
<br>
<a href="../index.html">Up to parent directory</a>
<hr>
<div class="changes">
<div class="h3-alike">Legal Information</div>
<input type="checkbox">
<div class="show-hide">
<p>
Intel and the Intel logo are trademarks of Intel Corporation in the U.S. and/or other countries.
<br>* Other names and brands may be claimed as the property of others.
<br>&copy; 2020, Intel Corporation
</p>
</div>
</div>
</body>
</html>

View File

@@ -0,0 +1,144 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include "seismic_video.h"
#include "universe.h"
#include "tbb/global_control.h"
const char * const SeismicVideo::titles[2] = {"Seismic Simulation: Serial", "Seismic Simulation: Parallel"};
void SeismicVideo::on_mouse(int x, int y, int key) {
if(key == 1){
u_.TryPutNewPulseSource(x,y);
}
}
void SeismicVideo::on_key(int key) {
key &= 0xff;
if(char(key) == ' ') initIsParallel = !initIsParallel;
else if(char(key) == 'p') initIsParallel = true;
else if(char(key) == 's') initIsParallel = false;
else if(char(key) == 'e') updating = true;
else if(char(key) == 'd') updating = false;
else if(key == 27) running = false;
title = titles[initIsParallel?1:0];
}
void SeismicVideo::on_process() {
tbb::global_control c(tbb::global_control::max_allowed_parallelism, threadsHigh);
for( int frames = 0; numberOfFrames_==0 || frames<numberOfFrames_; ++frames ) {
if( initIsParallel )
u_.ParallelUpdateUniverse();
else
u_.SerialUpdateUniverse();
if( !next_frame() ) break;
}
}
#ifdef _WINDOWS
#include "msvs/resource.h"
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
SeismicVideo * gVideo = NULL;
#endif
SeismicVideo::SeismicVideo( Universe &u, int number_of_frames, int threads_high, bool init_is_parallel)
:numberOfFrames_(number_of_frames),initIsParallel(init_is_parallel),u_(u),threadsHigh(threads_high)
{
title = titles[initIsParallel?1:0];
#ifdef _WINDOWS
gVideo = this;
LoadStringA(video::win_hInstance, IDC_SEISMICSIMULATION, szWindowClass, MAX_LOADSTRING);
memset(&wcex, 0, sizeof(wcex));
wcex.lpfnWndProc = (WNDPROC)WndProc;
wcex.hIcon = LoadIcon(video::win_hInstance, MAKEINTRESOURCE(IDI_SEISMICSIMULATION));
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = LPCTSTR(IDC_SEISMICSIMULATION);
wcex.lpszClassName = szWindowClass;
wcex.hIconSm = LoadIcon(video::win_hInstance, MAKEINTRESOURCE(IDI_SMALL));
win_set_class(wcex); // ascii convention here
win_load_accelerators(IDC_SEISMICSIMULATION);
#endif
}
#ifdef _WINDOWS
//
// FUNCTION: WndProc(HWND, unsigned, WORD, LONG)
//
// PURPOSE: Processes messages for the main window.
//
// WM_COMMAND - process the application menu
// WM_PAINT - Paint the main window
// WM_DESTROY - post a quit message and return
//
//
LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_INITDIALOG: return TRUE;
case WM_COMMAND:
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) {
EndDialog(hDlg, LOWORD(wParam));
return TRUE;
}
break;
}
return FALSE;
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId;
switch (message) {
case WM_COMMAND:
wmId = LOWORD(wParam);
// Parse the menu selections:
switch (wmId)
{
case IDM_ABOUT:
DialogBox(video::win_hInstance, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, (DLGPROC)About);
break;
case IDM_EXIT:
PostQuitMessage(0);
break;
case ID_FILE_PARALLEL:
gVideo->on_key('p');
break;
case ID_FILE_SERIAL:
gVideo->on_key('s');
break;
case ID_FILE_ENABLEGUI:
gVideo->on_key('e');
break;
case ID_FILE_DISABLEGUI:
gVideo->on_key('d');
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
#endif

View File

@@ -0,0 +1,50 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#ifndef SEISMIC_VIDEO_H_
#define SEISMIC_VIDEO_H_
#include "../../common/gui/video.h"
class Universe;
class SeismicVideo : public video
{
#ifdef _WINDOWS
#define MAX_LOADSTRING 100
TCHAR szWindowClass[MAX_LOADSTRING]; // the main window class name
WNDCLASSEX wcex;
#endif
static const char * const titles[2];
bool initIsParallel ;
Universe &u_;
int numberOfFrames_; // 0 means forever, positive means number of frames, negative is undefined
int threadsHigh;
private:
void on_mouse(int x, int y, int key);
void on_process();
#ifdef _WINDOWS
public:
#endif
void on_key(int key);
public:
SeismicVideo( Universe &u,int numberOfFrames, int threadsHigh, bool initIsParallel=true);
};
#endif /* SEISMIC_VIDEO_H_ */

View File

@@ -0,0 +1,217 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include "../../common/gui/video.h"
#include <cmath>
#include "tbb/blocked_range.h"
#include "tbb/parallel_for.h"
using namespace std;
#ifdef _MSC_VER
// warning C4068: unknown pragma
#pragma warning(disable: 4068)
// warning C4351: new behavior: elements of array 'array' will be default initialized
#pragma warning(disable: 4351)
#endif
#include "universe.h"
const colorcomp_t MaterialColor[4][3] = { // BGR
{96,0,0}, // WATER
{0,48,48}, // SANDSTONE
{32,32,23} // SHALE
};
void Universe::InitializeUniverse(video const& colorizer) {
pulseCounter = pulseTime = 100;
pulseX = UniverseWidth/3;
pulseY = UniverseHeight/4;
// Initialize V, S, and T to slightly non-zero values, in order to avoid denormal waves.
for( int i=0; i<UniverseHeight; ++i )
#pragma ivdep
for( int j=0; j<UniverseWidth; ++j ) {
T[i][j] = S[i][j] = V[i][j] = ValueType(1.0E-6);
}
for( int i=1; i<UniverseHeight-1; ++i ) {
for( int j=1; j<UniverseWidth-1; ++j ) {
float x = float(j-UniverseWidth/2)/(UniverseWidth/2);
ValueType t = (ValueType)i/UniverseHeight;
MaterialType m;
D[i][j] = 1.0;
// Coefficient values are fictitious, and chosen to visually exaggerate
// physical effects such as Rayleigh waves. The fabs/exp line generates
// a shale layer with a gentle upwards slope and an anticline.
if( t<0.3f ) {
m = WATER;
M[i][j] = 0.125;
L[i][j] = 0.125;
} else if( fabs(t-0.7+0.2*exp(-8*x*x)+0.025*x)<=0.1 ) {
m = SHALE;
M[i][j] = 0.5;
L[i][j] = 0.6;
} else {
m = SANDSTONE;
M[i][j] = 0.3;
L[i][j] = 0.4;
}
material[i][j] = m;
}
}
ValueType scale = 2.0f/ColorMapSize;
for( int k=0; k<4; ++k ) {
for( int i=0; i<ColorMapSize; ++i ) {
colorcomp_t c[3];
ValueType t = (i-ColorMapSize/2)*scale;
ValueType r = t>0 ? t : 0;
ValueType b = t<0 ? -t : 0;
ValueType g = 0.5f*fabs(t);
memcpy(c, MaterialColor[k], sizeof(c));
c[2] = colorcomp_t(r*(255-c[2])+c[2]);
c[1] = colorcomp_t(g*(255-c[1])+c[1]);
c[0] = colorcomp_t(b*(255-c[0])+c[0]);
ColorMap[k][i] = colorizer.get_color(c[2], c[1], c[0]);
}
}
// Set damping coefficients around border to reduce reflections from boundaries.
ValueType d = 1.0;
for( int k=DamperSize-1; k>0; --k ) {
d *= 1-1.0f/(DamperSize*DamperSize);
for( int j=1; j<UniverseWidth-1; ++j ) {
D[k][j] *= d;
D[UniverseHeight-1-k][j] *= d;
}
for( int i=1; i<UniverseHeight-1; ++i ) {
D[i][k] *= d;
D[i][UniverseWidth-1-k] *= d;
}
}
drawingMemory = colorizer.get_drawing_memory();
}
void Universe::UpdatePulse() {
if( pulseCounter>0 ) {
ValueType t = (pulseCounter-pulseTime/2)*0.05f;
V[pulseY][pulseX] += 64*sqrt(M[pulseY][pulseX])*exp(-t*t);
--pulseCounter;
}
}
struct Universe::Rectangle {
struct std::pair<int,int> xRange;
struct std::pair<int,int> yRange;
Rectangle (int startX, int startY, int width, int height):xRange(startX,width),yRange(startY,height){}
int StartX() const {return xRange.first;}
int StartY() const {return yRange.first;}
int Width() const {return xRange.second;}
int Height() const {return yRange.second;}
int EndX() const {return xRange.first + xRange.second;}
int EndY() const {return yRange.first + yRange.second;}
};
void Universe::UpdateStress(Rectangle const& r ) {
drawing_area drawing(r.StartX(),r.StartY(),r.Width(),r.Height(),drawingMemory);
for( int i=r.StartY(); i<r.EndY() ; ++i ) {
drawing.set_pos(1, i-r.StartY());
#pragma ivdep
for( int j=r.StartX(); j<r.EndX() ; ++j ) {
S[i][j] += M[i][j]*(V[i][j+1]-V[i][j]);
T[i][j] += M[i][j]*(V[i+1][j]-V[i][j]);
int index = (int)(V[i][j]*(ColorMapSize/2)) + ColorMapSize/2;
if( index<0 ) index = 0;
if( index>=ColorMapSize ) index = ColorMapSize-1;
color_t* c = ColorMap[material[i][j]];
drawing.put_pixel(c[index]);
}
}
}
void Universe::SerialUpdateStress() {
Rectangle area(0, 0, UniverseWidth-1, UniverseHeight-1);
UpdateStress(area);
}
struct UpdateStressBody {
Universe & u_;
UpdateStressBody(Universe & u):u_(u){}
void operator()( const tbb::blocked_range<int>& range ) const {
Universe::Rectangle area(0, range.begin(), u_.UniverseWidth-1, range.size());
u_.UpdateStress(area);
}
};
void Universe::ParallelUpdateStress(tbb::affinity_partitioner &affinity) {
tbb::parallel_for( tbb::blocked_range<int>( 0, UniverseHeight-1 ), // Index space for loop
UpdateStressBody(*this), // Body of loop
affinity ); // Affinity hint
}
void Universe::UpdateVelocity(Rectangle const& r) {
for( int i=r.StartY(); i<r.EndY(); ++i )
#pragma ivdep
for( int j=r.StartX(); j<r.EndX(); ++j )
V[i][j] = D[i][j]*(V[i][j] + L[i][j]*(S[i][j] - S[i][j-1] + T[i][j] - T[i-1][j]));
}
void Universe::SerialUpdateVelocity() {
UpdateVelocity(Rectangle(1,1,UniverseWidth-1,UniverseHeight-1));
}
struct UpdateVelocityBody {
Universe & u_;
UpdateVelocityBody(Universe & u):u_(u){}
void operator()( const tbb::blocked_range<int>& y_range ) const {
u_.UpdateVelocity(Universe::Rectangle(1,y_range.begin(),u_.UniverseWidth-1,y_range.size()));
}
};
void Universe::ParallelUpdateVelocity(tbb::affinity_partitioner &affinity) {
tbb::parallel_for( tbb::blocked_range<int>( 1, UniverseHeight ), // Index space for loop
UpdateVelocityBody(*this), // Body of loop
affinity ); // Affinity hint
}
void Universe::SerialUpdateUniverse() {
UpdatePulse();
SerialUpdateStress();
SerialUpdateVelocity();
}
void Universe::ParallelUpdateUniverse() {
/** Affinity is an argument to parallel_for to hint that an iteration of a loop
is best replayed on the same processor for each execution of the loop.
It is a static object because it must remember where the iterations happened
in previous executions. */
static tbb::affinity_partitioner affinity;
UpdatePulse();
ParallelUpdateStress(affinity);
ParallelUpdateVelocity(affinity);
}
bool Universe::TryPutNewPulseSource(int x, int y){
if(pulseCounter == 0) {
pulseCounter = pulseTime;
pulseX = x; pulseY = y;
return true;
}
return false;
}
void Universe::SetDrawingMemory(const drawing_memory &dmem) {
drawingMemory = dmem;
}

View File

@@ -0,0 +1,114 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#ifndef UNIVERSE_H_
#define UNIVERSE_H_
#ifndef UNIVERSE_WIDTH
#define UNIVERSE_WIDTH 1024
#endif
#ifndef UNIVERSE_HEIGHT
#define UNIVERSE_HEIGHT 512
#endif
#include "../../common/gui/video.h"
#include "tbb/partitioner.h"
class Universe {
public:
enum {
UniverseWidth = UNIVERSE_WIDTH,
UniverseHeight = UNIVERSE_HEIGHT
};
private:
//in order to avoid performance degradation due to cache aliasing issue
//some padding is needed after each row in array, and between array themselves.
//the padding is achieved by adjusting number of rows and columns.
//as the compiler is forced to place class members of the same clause in order of the
//declaration this seems to be the right way of padding.
//magic constants added below are chosen experimentally for 1024x512.
enum {
MaxWidth = UniverseWidth+1,
MaxHeight = UniverseHeight+3
};
typedef float ValueType;
//! Horizontal stress
ValueType S[MaxHeight][MaxWidth];
//! Velocity at each grid point
ValueType V[MaxHeight][MaxWidth];
//! Vertical stress
ValueType T[MaxHeight][MaxWidth];
//! Coefficient related to modulus
ValueType M[MaxHeight][MaxWidth];
//! Damping coefficients
ValueType D[MaxHeight][MaxWidth];
//! Coefficient related to lightness
ValueType L[MaxHeight][MaxWidth];
enum { ColorMapSize = 1024};
color_t ColorMap[4][ColorMapSize];
enum MaterialType {
WATER=0,
SANDSTONE=1,
SHALE=2
};
//! Values are MaterialType, cast to an unsigned char to save space.
unsigned char material[MaxHeight][MaxWidth];
private:
enum { DamperSize = 32};
int pulseTime;
int pulseCounter;
int pulseX;
int pulseY;
drawing_memory drawingMemory;
public:
void InitializeUniverse(video const& colorizer);
void SerialUpdateUniverse();
void ParallelUpdateUniverse();
bool TryPutNewPulseSource(int x, int y);
void SetDrawingMemory(const drawing_memory &dmem);
private:
struct Rectangle;
void UpdatePulse();
void UpdateStress(Rectangle const& r );
void SerialUpdateStress() ;
friend struct UpdateStressBody;
friend struct UpdateVelocityBody;
void ParallelUpdateStress(tbb::affinity_partitioner &affinity);
void UpdateVelocity(Rectangle const& r);
void SerialUpdateVelocity() ;
void ParallelUpdateVelocity(tbb::affinity_partitioner &affinity);
};
#endif /* UNIVERSE_H_ */

View File

@@ -0,0 +1,586 @@
// !$*UTF8*$!
{
archiveVersion = 1;
classes = {
};
objectVersion = 46;
objects = {
/* Begin PBXBuildFile section */
84B8DA78152CA90100D59B95 /* OpenGLView.m in Sources */ = {isa = PBXBuildFile; fileRef = 84B8DA71152CA90100D59B95 /* OpenGLView.m */; };
84B8DA79152CA90100D59B95 /* tbbAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 84B8DA73152CA90100D59B95 /* tbbAppDelegate.m */; };
84B8DA7A152CA90100D59B95 /* (null) in Resources */ = {isa = PBXBuildFile; };
84B8DA80152CA97B00D59B95 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 84B8DA7C152CA97B00D59B95 /* InfoPlist.strings */; };
84B8DA81152CA97B00D59B95 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 84B8DA7E152CA97B00D59B95 /* MainMenu.xib */; };
84B8DA87152CA99C00D59B95 /* main.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 84B8DA82152CA99C00D59B95 /* main.cpp */; };
84B8DA88152CA99C00D59B95 /* seismic_video.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 84B8DA83152CA99C00D59B95 /* seismic_video.cpp */; };
84B8DA89152CA99C00D59B95 /* universe.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 84B8DA85152CA99C00D59B95 /* universe.cpp */; };
84D017561527431F0008A4E0 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 84D017551527431F0008A4E0 /* Cocoa.framework */; };
84D01776152744BD0008A4E0 /* OpenGL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 84D01775152744BD0008A4E0 /* OpenGL.framework */; };
D3BD96921C0DD55E00163D8B /* main.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 84B8DA82152CA99C00D59B95 /* main.cpp */; };
D3BD96931C0DD56900163D8B /* seismic_video.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 84B8DA83152CA99C00D59B95 /* seismic_video.cpp */; };
D3BD96941C0DD57600163D8B /* universe.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 84B8DA85152CA99C00D59B95 /* universe.cpp */; };
D3BD96951C0DD59200163D8B /* macvideo.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 84B8DA99152CADF400D59B95 /* macvideo.cpp */; };
D3BD96961C0DD5A000163D8B /* OpenGLView.m in Sources */ = {isa = PBXBuildFile; fileRef = 84B8DA71152CA90100D59B95 /* OpenGLView.m */; };
D3BD96971C0DD5A900163D8B /* tbbAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 84B8DA73152CA90100D59B95 /* tbbAppDelegate.m */; };
D3BD96A31C0DE2BB00163D8B /* macvideo.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 84B8DA99152CADF400D59B95 /* macvideo.cpp */; };
D3BD96A61C0DE3DE00163D8B /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = D3BD96A51C0DE3DE00163D8B /* main.m */; };
D3BD96AB1C0E08E500163D8B /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = D3BD96A51C0DE3DE00163D8B /* main.m */; };
D3BD96B31C0E0AFE00163D8B /* tbbExample-Info.ios.plist in Resources */ = {isa = PBXBuildFile; fileRef = D3BD966D1C0DD00400163D8B /* tbbExample-Info.ios.plist */; };
D3BD96B51C0E0B2200163D8B /* tbbExample-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = D3BD96B41C0E0B2200163D8B /* tbbExample-Info.plist */; };
D3BD96B81C0E11CE00163D8B /* iOS.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = D3BD96B61C0E11C600163D8B /* iOS.storyboard */; };
/* End PBXBuildFile section */
/* Begin PBXBuildRule section */
C3C5896E2191923E00DAC94C /* PBXBuildRule */ = {
isa = PBXBuildRule;
compilerSpec = com.intel.compilers.icc.latest;
fileType = sourcecode.cpp;
isEditable = 1;
outputFiles = (
);
script = "# Type a script or drag a script file from your workspace to insert its path.\n";
};
C3C5896F2191925E00DAC94C /* PBXBuildRule */ = {
isa = PBXBuildRule;
compilerSpec = com.intel.compilers.icc.latest;
fileType = sourcecode.cpp;
isEditable = 1;
outputFiles = (
);
script = "# Type a script or drag a script file from your workspace to insert its path.\n";
};
/* End PBXBuildRule section */
/* Begin PBXFileReference section */
84B8DA70152CA90100D59B95 /* OpenGLView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OpenGLView.h; path = ../../../common/gui/xcode/tbbExample/OpenGLView.h; sourceTree = "<group>"; };
84B8DA71152CA90100D59B95 /* OpenGLView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OpenGLView.m; path = ../../../common/gui/xcode/tbbExample/OpenGLView.m; sourceTree = "<group>"; };
84B8DA72152CA90100D59B95 /* tbbAppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = tbbAppDelegate.h; path = ../../../common/gui/xcode/tbbExample/tbbAppDelegate.h; sourceTree = "<group>"; };
84B8DA73152CA90100D59B95 /* tbbAppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = tbbAppDelegate.m; path = ../../../common/gui/xcode/tbbExample/tbbAppDelegate.m; sourceTree = "<group>"; };
84B8DA75152CA90100D59B95 /* tbbExample-Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "tbbExample-Prefix.pch"; path = "../../../common/gui/xcode/tbbExample/tbbExample-Prefix.pch"; sourceTree = "<group>"; };
84B8DA7D152CA97B00D59B95 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = InfoPlist.strings; sourceTree = "<group>"; };
84B8DA7F152CA97B00D59B95 /* en */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = en; path = MainMenu.xib; sourceTree = "<group>"; };
84B8DA82152CA99C00D59B95 /* main.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = main.cpp; path = ../main.cpp; sourceTree = "<group>"; };
84B8DA83152CA99C00D59B95 /* seismic_video.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = seismic_video.cpp; path = ../seismic_video.cpp; sourceTree = "<group>"; };
84B8DA84152CA99C00D59B95 /* seismic_video.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = seismic_video.h; path = ../seismic_video.h; sourceTree = "<group>"; };
84B8DA85152CA99C00D59B95 /* universe.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = universe.cpp; path = ../universe.cpp; sourceTree = "<group>"; };
84B8DA86152CA99C00D59B95 /* universe.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = universe.h; path = ../universe.h; sourceTree = "<group>"; };
84B8DA99152CADF400D59B95 /* macvideo.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = macvideo.cpp; path = ../../../common/gui/macvideo.cpp; sourceTree = "<group>"; };
84D017511527431F0008A4E0 /* tbbExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = tbbExample.app; sourceTree = BUILT_PRODUCTS_DIR; };
84D017551527431F0008A4E0 /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = System/Library/Frameworks/Cocoa.framework; sourceTree = SDKROOT; };
84D017581527431F0008A4E0 /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = System/Library/Frameworks/AppKit.framework; sourceTree = SDKROOT; };
84D017591527431F0008A4E0 /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = System/Library/Frameworks/CoreData.framework; sourceTree = SDKROOT; };
84D0175A1527431F0008A4E0 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
84D01775152744BD0008A4E0 /* OpenGL.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OpenGL.framework; path = System/Library/Frameworks/OpenGL.framework; sourceTree = SDKROOT; };
D3BD966D1C0DD00400163D8B /* tbbExample-Info.ios.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; name = "tbbExample-Info.ios.plist"; path = "../../../common/gui/xcode/tbbExample/tbbExample-Info.ios.plist"; sourceTree = "<group>"; };
D3BD96A51C0DE3DE00163D8B /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = main.m; path = ../../../common/gui/xcode/tbbExample/main.m; sourceTree = "<group>"; };
D3BD96B41C0E0B2200163D8B /* tbbExample-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = "tbbExample-Info.plist"; path = "../../../common/gui/xcode/tbbExample/tbbExample-Info.plist"; sourceTree = "<group>"; };
D3BD96B61C0E11C600163D8B /* iOS.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; name = iOS.storyboard; path = ../iOS.storyboard; sourceTree = "<group>"; };
D3BD96BB1C0E19E700163D8B /* tbbExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = tbbExample.app; sourceTree = BUILT_PRODUCTS_DIR; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
84D0174E1527431F0008A4E0 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
84D01776152744BD0008A4E0 /* OpenGL.framework in Frameworks */,
84D017561527431F0008A4E0 /* Cocoa.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
D3BD96571C0DD00400163D8B /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
84B8DA6C152CA8D900D59B95 /* tbbExample Sources */ = {
isa = PBXGroup;
children = (
84B8DA7B152CA97B00D59B95 /* Resources */,
84B8DA82152CA99C00D59B95 /* main.cpp */,
D3BD96A51C0DE3DE00163D8B /* main.m */,
84B8DA83152CA99C00D59B95 /* seismic_video.cpp */,
84B8DA84152CA99C00D59B95 /* seismic_video.h */,
84B8DA85152CA99C00D59B95 /* universe.cpp */,
84B8DA86152CA99C00D59B95 /* universe.h */,
);
name = "tbbExample Sources";
sourceTree = "<group>";
};
84B8DA7B152CA97B00D59B95 /* Resources */ = {
isa = PBXGroup;
children = (
D3BD96B61C0E11C600163D8B /* iOS.storyboard */,
84B8DA7C152CA97B00D59B95 /* InfoPlist.strings */,
84B8DA7E152CA97B00D59B95 /* MainMenu.xib */,
);
name = Resources;
path = ../../../common/gui/xcode/tbbExample/en.lproj;
sourceTree = "<group>";
};
84B8DA98152CAD8600D59B95 /* Gui layer */ = {
isa = PBXGroup;
children = (
84B8DA99152CADF400D59B95 /* macvideo.cpp */,
84B8DA70152CA90100D59B95 /* OpenGLView.h */,
84B8DA71152CA90100D59B95 /* OpenGLView.m */,
84B8DA72152CA90100D59B95 /* tbbAppDelegate.h */,
84B8DA73152CA90100D59B95 /* tbbAppDelegate.m */,
84B8DA75152CA90100D59B95 /* tbbExample-Prefix.pch */,
);
name = "Gui layer";
sourceTree = "<group>";
};
84D017461527431F0008A4E0 = {
isa = PBXGroup;
children = (
D3BD96B41C0E0B2200163D8B /* tbbExample-Info.plist */,
D3BD966D1C0DD00400163D8B /* tbbExample-Info.ios.plist */,
84B8DA98152CAD8600D59B95 /* Gui layer */,
84B8DA6C152CA8D900D59B95 /* tbbExample Sources */,
84D017541527431F0008A4E0 /* Frameworks */,
84D017521527431F0008A4E0 /* Products */,
);
sourceTree = "<group>";
};
84D017521527431F0008A4E0 /* Products */ = {
isa = PBXGroup;
children = (
84D017511527431F0008A4E0 /* tbbExample.app */,
D3BD96BB1C0E19E700163D8B /* tbbExample.app */,
);
name = Products;
sourceTree = "<group>";
};
84D017541527431F0008A4E0 /* Frameworks */ = {
isa = PBXGroup;
children = (
84D017591527431F0008A4E0 /* CoreData.framework */,
84D0175A1527431F0008A4E0 /* Foundation.framework */,
84D017581527431F0008A4E0 /* AppKit.framework */,
84D01775152744BD0008A4E0 /* OpenGL.framework */,
84D017551527431F0008A4E0 /* Cocoa.framework */,
);
name = Frameworks;
sourceTree = "<group>";
};
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
84D017501527431F0008A4E0 /* tbbExample */ = {
isa = PBXNativeTarget;
buildConfigurationList = 84D01772152743200008A4E0 /* Build configuration list for PBXNativeTarget "tbbExample" */;
buildPhases = (
84D0174D1527431F0008A4E0 /* Sources */,
84D0174E1527431F0008A4E0 /* Frameworks */,
84D0174F1527431F0008A4E0 /* Resources */,
);
buildRules = (
C3C5896E2191923E00DAC94C /* PBXBuildRule */,
);
dependencies = (
);
name = tbbExample;
productName = tbbExample;
productReference = 84D017511527431F0008A4E0 /* tbbExample.app */;
productType = "com.apple.product-type.application";
};
D3BD96591C0DD00400163D8B /* tbbExample_ios */ = {
isa = PBXNativeTarget;
buildConfigurationList = D3BD96841C0DD00500163D8B /* Build configuration list for PBXNativeTarget "tbbExample_ios" */;
buildPhases = (
D3BD96561C0DD00400163D8B /* Sources */,
D3BD96571C0DD00400163D8B /* Frameworks */,
D3BD96581C0DD00400163D8B /* Resources */,
);
buildRules = (
C3C5896F2191925E00DAC94C /* PBXBuildRule */,
);
dependencies = (
);
name = tbbExample_ios;
productName = tbbExample_ios;
productReference = D3BD96BB1C0E19E700163D8B /* tbbExample.app */;
productType = "com.apple.product-type.application";
};
/* End PBXNativeTarget section */
/* Begin PBXProject section */
84D017481527431F0008A4E0 /* Project object */ = {
isa = PBXProject;
attributes = {
CLASSPREFIX = tbb;
LastUpgradeCheck = 0710;
TargetAttributes = {
D3BD96591C0DD00400163D8B = {
CreatedOnToolsVersion = 7.1.1;
DevelopmentTeam = 7J8M3RM94C;
};
};
};
buildConfigurationList = 84D0174B1527431F0008A4E0 /* Build configuration list for PBXProject "seismic" */;
compatibilityVersion = "Xcode 3.2";
developmentRegion = English;
hasScannedForEncodings = 0;
knownRegions = (
en,
Base,
);
mainGroup = 84D017461527431F0008A4E0;
productRefGroup = 84D017521527431F0008A4E0 /* Products */;
projectDirPath = "";
projectRoot = "";
targets = (
84D017501527431F0008A4E0 /* tbbExample */,
D3BD96591C0DD00400163D8B /* tbbExample_ios */,
);
};
/* End PBXProject section */
/* Begin PBXResourcesBuildPhase section */
84D0174F1527431F0008A4E0 /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
D3BD96B51C0E0B2200163D8B /* tbbExample-Info.plist in Resources */,
84B8DA7A152CA90100D59B95 /* (null) in Resources */,
84B8DA80152CA97B00D59B95 /* InfoPlist.strings in Resources */,
84B8DA81152CA97B00D59B95 /* MainMenu.xib in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
D3BD96581C0DD00400163D8B /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
D3BD96B81C0E11CE00163D8B /* iOS.storyboard in Resources */,
D3BD96B31C0E0AFE00163D8B /* tbbExample-Info.ios.plist in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXResourcesBuildPhase section */
/* Begin PBXSourcesBuildPhase section */
84D0174D1527431F0008A4E0 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
84B8DA78152CA90100D59B95 /* OpenGLView.m in Sources */,
84B8DA79152CA90100D59B95 /* tbbAppDelegate.m in Sources */,
84B8DA87152CA99C00D59B95 /* main.cpp in Sources */,
D3BD96A31C0DE2BB00163D8B /* macvideo.cpp in Sources */,
84B8DA88152CA99C00D59B95 /* seismic_video.cpp in Sources */,
D3BD96A61C0DE3DE00163D8B /* main.m in Sources */,
84B8DA89152CA99C00D59B95 /* universe.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
D3BD96561C0DD00400163D8B /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
D3BD96941C0DD57600163D8B /* universe.cpp in Sources */,
D3BD96921C0DD55E00163D8B /* main.cpp in Sources */,
D3BD96951C0DD59200163D8B /* macvideo.cpp in Sources */,
D3BD96931C0DD56900163D8B /* seismic_video.cpp in Sources */,
D3BD96971C0DD5A900163D8B /* tbbAppDelegate.m in Sources */,
D3BD96AB1C0E08E500163D8B /* main.m in Sources */,
D3BD96961C0DD5A000163D8B /* OpenGLView.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXSourcesBuildPhase section */
/* Begin PBXVariantGroup section */
84B8DA7C152CA97B00D59B95 /* InfoPlist.strings */ = {
isa = PBXVariantGroup;
children = (
84B8DA7D152CA97B00D59B95 /* en */,
);
name = InfoPlist.strings;
sourceTree = "<group>";
};
84B8DA7E152CA97B00D59B95 /* MainMenu.xib */ = {
isa = PBXVariantGroup;
children = (
84B8DA7F152CA97B00D59B95 /* en */,
);
name = MainMenu.xib;
sourceTree = "<group>";
};
/* End PBXVariantGroup section */
/* Begin XCBuildConfiguration section */
84D01770152743200008A4E0 /* Debug64 */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_CXX_LANGUAGE_STANDARD = "c++11";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = c11;
GCC_DYNAMIC_NO_PIC = NO;
GCC_ENABLE_OBJC_EXCEPTIONS = YES;
GCC_INCREASE_PRECOMPILED_HEADER_SHARING = NO;
GCC_NO_COMMON_BLOCKS = YES;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
"$(inherited)",
);
GCC_SYMBOLS_PRIVATE_EXTERN = NO;
GCC_VERSION = "";
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
HEADER_SEARCH_PATHS = (
"$(TBBROOT)/include",
/opt/intel/tbb/include,
);
ICC_CXX_LANG_DIALECT = "c++11";
ICC_TBB = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = "$(TBBROOT)/lib /opt/intel/tbb/lib";
LIBRARY_SEARCH_PATHS = (
"$(TBBROOT)/lib",
/opt/intel/tbb/lib,
);
MACOSX_DEPLOYMENT_TARGET = 10.11;
ONLY_ACTIVE_ARCH = YES;
OTHER_LDFLAGS = (
"-m64",
"-ltbb_debug",
);
SDKROOT = macosx;
VALID_ARCHS = x86_64;
};
name = Debug64;
};
84D01771152743200008A4E0 /* Release64 */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_CXX_LANGUAGE_STANDARD = "c++11";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = YES;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = c11;
GCC_ENABLE_OBJC_EXCEPTIONS = YES;
GCC_INCREASE_PRECOMPILED_HEADER_SHARING = NO;
GCC_NO_COMMON_BLOCKS = YES;
GCC_VERSION = "";
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
HEADER_SEARCH_PATHS = (
"$(TBBROOT)/include",
/opt/intel/tbb/include,
);
ICC_CXX_LANG_DIALECT = "c++11";
ICC_TBB = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = "$(TBBROOT)/lib /opt/intel/tbb/lib";
LIBRARY_SEARCH_PATHS = (
"$(TBBROOT)/lib",
/opt/intel/tbb/lib,
);
MACOSX_DEPLOYMENT_TARGET = 10.11;
OTHER_LDFLAGS = (
"-m64",
"-ltbb",
);
SDKROOT = macosx;
VALID_ARCHS = x86_64;
};
name = Release64;
};
84D01773152743200008A4E0 /* Debug64 */ = {
isa = XCBuildConfiguration;
buildSettings = {
ARCHS = "$(ARCHS_STANDARD)";
CLANG_ENABLE_OBJC_ARC = NO;
COMBINE_HIDPI_IMAGES = YES;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "../../../common/gui/xcode/tbbExample/tbbExample-Prefix.pch";
HEADER_SEARCH_PATHS = "$(inherited)";
INFOPLIST_FILE = "../../../common/gui/xcode/tbbExample/tbbExample-Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited)";
LIBRARY_SEARCH_PATHS = "$(inherited)";
MACOSX_DEPLOYMENT_TARGET = 10.11;
PRODUCT_BUNDLE_IDENTIFIER = "Intel.${PRODUCT_NAME:rfc1034identifier}";
PRODUCT_NAME = "$(TARGET_NAME)";
RUN_CLANG_STATIC_ANALYZER = YES;
USER_HEADER_SEARCH_PATHS = "";
VERSION_INFO_BUILDER = "$(TARGET_NAME)";
WRAPPER_EXTENSION = app;
};
name = Debug64;
};
84D01774152743200008A4E0 /* Release64 */ = {
isa = XCBuildConfiguration;
buildSettings = {
ARCHS = "$(ARCHS_STANDARD)";
CLANG_ENABLE_OBJC_ARC = NO;
COMBINE_HIDPI_IMAGES = YES;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "../../../common/gui/xcode/tbbExample/tbbExample-Prefix.pch";
HEADER_SEARCH_PATHS = "$(inherited)";
INFOPLIST_FILE = "../../../common/gui/xcode/tbbExample/tbbExample-Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited)";
LIBRARY_SEARCH_PATHS = "$(inherited)";
MACOSX_DEPLOYMENT_TARGET = 10.11;
PRODUCT_BUNDLE_IDENTIFIER = "Intel.${PRODUCT_NAME:rfc1034identifier}";
PRODUCT_NAME = "$(TARGET_NAME)";
RUN_CLANG_STATIC_ANALYZER = YES;
USER_HEADER_SEARCH_PATHS = "";
VERSION_INFO_BUILDER = "$(TARGET_NAME)";
WRAPPER_EXTENSION = app;
};
name = Release64;
};
D3BD96851C0DD00500163D8B /* Debug64 */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
DEBUG_INFORMATION_FORMAT = dwarf;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
GCC_NO_COMMON_BLOCKS = YES;
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
"$(inherited)",
"__TBB_IOS=1",
);
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
INFOPLIST_FILE = "../../../common/gui/xcode/tbbExample/tbbExample-Info.ios.plist";
IPHONEOS_DEPLOYMENT_TARGET = 9.1;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path";
LIBRARY_SEARCH_PATHS = "\"$(SRCROOT)/../../../../lib/ios\"";
MTL_ENABLE_DEBUG_INFO = YES;
PRODUCT_BUNDLE_IDENTIFIER = com.tbb.example;
PRODUCT_NAME = tbbExample;
SDKROOT = iphoneos;
TARGETED_DEVICE_FAMILY = 1;
};
name = Debug64;
};
D3BD96861C0DD00500163D8B /* Release64 */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = NO;
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_NO_COMMON_BLOCKS = YES;
GCC_PREPROCESSOR_DEFINITIONS = "__TBB_IOS=1";
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
INFOPLIST_FILE = "../../../common/gui/xcode/tbbExample/tbbExample-Info.ios.plist";
IPHONEOS_DEPLOYMENT_TARGET = 9.1;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path";
LIBRARY_SEARCH_PATHS = "\"$(SRCROOT)/../../../../lib/ios\"";
MTL_ENABLE_DEBUG_INFO = NO;
PRODUCT_BUNDLE_IDENTIFIER = com.tbb.example;
PRODUCT_NAME = tbbExample;
SDKROOT = iphoneos;
TARGETED_DEVICE_FAMILY = 1;
VALIDATE_PRODUCT = YES;
};
name = Release64;
};
/* End XCBuildConfiguration section */
/* Begin XCConfigurationList section */
84D0174B1527431F0008A4E0 /* Build configuration list for PBXProject "seismic" */ = {
isa = XCConfigurationList;
buildConfigurations = (
84D01770152743200008A4E0 /* Debug64 */,
84D01771152743200008A4E0 /* Release64 */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release64;
};
84D01772152743200008A4E0 /* Build configuration list for PBXNativeTarget "tbbExample" */ = {
isa = XCConfigurationList;
buildConfigurations = (
84D01773152743200008A4E0 /* Debug64 */,
84D01774152743200008A4E0 /* Release64 */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release64;
};
D3BD96841C0DD00500163D8B /* Build configuration list for PBXNativeTarget "tbbExample_ios" */ = {
isa = XCConfigurationList;
buildConfigurations = (
D3BD96851C0DD00500163D8B /* Debug64 */,
D3BD96861C0DD00500163D8B /* Release64 */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release64;
};
/* End XCConfigurationList section */
};
rootObject = 84D017481527431F0008A4E0 /* Project object */;
}

View File

@@ -0,0 +1,119 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0710"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "D3BD96591C0DD00400163D8B"
BuildableName = "tbbExample.app"
BlueprintName = "tbbExample_ios"
ReferencedContainer = "container:seismic.xcodeproj">
</BuildableReference>
</BuildActionEntry>
<BuildActionEntry
buildForTesting = "NO"
buildForRunning = "NO"
buildForProfiling = "NO"
buildForArchiving = "NO"
buildForAnalyzing = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "D3BD96711C0DD00400163D8B"
BuildableName = "com.tbb.exampleTests.xctest"
BlueprintName = "com.tbb.exampleTests"
ReferencedContainer = "container:seismic.xcodeproj">
</BuildableReference>
</BuildActionEntry>
<BuildActionEntry
buildForTesting = "NO"
buildForRunning = "NO"
buildForProfiling = "NO"
buildForArchiving = "NO"
buildForAnalyzing = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "D3BD967C1C0DD00500163D8B"
BuildableName = "com.tbb.exampleUITests.xctest"
BlueprintName = "com.tbb.exampleUITests"
ReferencedContainer = "container:seismic.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "D3BD96591C0DD00400163D8B"
BuildableName = "tbbExample.app"
BlueprintName = "tbbExample_ios"
ReferencedContainer = "container:seismic.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "D3BD96591C0DD00400163D8B"
BuildableName = "tbbExample.app"
BlueprintName = "tbbExample_ios"
ReferencedContainer = "container:seismic.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "D3BD96591C0DD00400163D8B"
BuildableName = "tbbExample.app"
BlueprintName = "tbbExample_ios"
ReferencedContainer = "container:seismic.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>

View File

@@ -0,0 +1,99 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0710"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "84D017501527431F0008A4E0"
BuildableName = "tbbExample.app"
BlueprintName = "tbbExample"
ReferencedContainer = "container:tbbExample.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "84D017501527431F0008A4E0"
BuildableName = "tbbExample.app"
BlueprintName = "tbbExample"
ReferencedContainer = "container:seismic.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
customWorkingDirectory = "/tmp"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "NO"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "84D017501527431F0008A4E0"
BuildableName = "tbbExample.app"
BlueprintName = "tbbExample"
ReferencedContainer = "container:seismic.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<EnvironmentVariables>
<EnvironmentVariable
key = "DYLD_LIBRARY_PATH"
value = "$(SRCROOT)/../../../../lib"
isEnabled = "YES">
</EnvironmentVariable>
</EnvironmentVariables>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "84D017501527431F0008A4E0"
BuildableName = "tbbExample.app"
BlueprintName = "tbbExample"
ReferencedContainer = "container:tbbExample.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>

View File

@@ -0,0 +1,147 @@
# Copyright (c) 2005-2020 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# The original source for this example is
# Copyright (c) 1994-2008 John E. Stone
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# 3. The name of the author may not be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
# Common Makefile that builds and runs example.
# Trying to find if icl.exe is set
CXX1 = $(TBB_CXX)-
CXX2 = $(CXX1:icl.exe-=icl.exe)
CXX = $(CXX2:-=cl.exe)
# Uncomment one of next lines to choose user interface type (console, gdiplus, direct draw)
#UI = con
UI = gdi
#UI = dd
# Machine architecture, auto-detected from TBB_TARGET_ARCH by default
# Use XARCH variable to change it. See index.html for more information
ARCH0 = $(TBB_TARGET_ARCH)-
ARCH1 = $(ARCH0:ia32-=x86)
ARCH2 = $(ARCH1:intel64-=AMD64)
XARCH = $(ARCH2:-=x86)
# The default runtime arguments
DATASET = balls
override ARGS := dat\$(DATASET).dat $(ARGS)
PERF_RUN_ARGS = silent dat\balls3.dat
LIGHT_ARGS = dat\model2.dat
# Add these for tbb/tbb1d release builds
# /GL is a workaround to prevent run-time crash when built by VS2010
CXXFLAGS_TBB_NDEBUG = $(CXXFLAGS) /GL
LIBS_TBB_NDEBUG = tbb.lib $(LIBS)
# Add these for tbb/tbb1d debug builds
CXXFLAGS_TBB_DEBUG = $(CXXFLAGS) /D TBB_USE_DEBUG
LIBS_TBB_DEBUG = tbb_debug.lib $(LIBS)
MAKEINC = ../../common/gui/Makefile.win
# scr/main.cpp src/tachyon_video.cpp cannot be included to the SOURCE_COMMON list since it depends on UI and /subsystem which is not specified for common SOURCE build
SOURCE = src/main.cpp src/tachyon_video.cpp
SOURCE_COMMON = src/pthread.cpp src/api.cpp src/apigeom.cpp src/apitrigeom.cpp src/bndbox.cpp src/box.cpp src/camera.cpp src/coordsys.cpp src/cylinder.cpp src/extvol.cpp src/global.cpp src/grid.cpp src/imageio.cpp src/imap.cpp src/intersect.cpp src/jpeg.cpp src/light.cpp src/objbound.cpp src/parse.cpp src/plane.cpp src/ppm.cpp src/quadric.cpp src/render.cpp src/ring.cpp src/shade.cpp src/sphere.cpp src/texture.cpp src/tgafile.cpp src/trace_rest.cpp src/triangle.cpp src/ui.cpp src/util.cpp src/vector.cpp src/vol.cpp
# Targets
all: build run
release: build
debug: build_debug
test: run
build: build_serial build_tbb1d build_tbb
build_debug: build_serial_debug build_tbb1d_debug build_tbb_debug
run: run_serial run_tbb1d run_tbb
serial: build_serial run_serial
serial_debug: build_serial_debug run_serial
tbb: build_tbb run_tbb
tbb_debug: build_tbb_debug run_tbb
tbb1d: build_tbb1d run_tbb1d
tbb1d_debug: build_tbb1d_debug run_tbb1d
CXXFLAGS_COMMON = /c /nologo /EHsc /Zc:forScope /D WIN32 /D _MBCS /D _CRT_SECURE_NO_DEPRECATE /Foobj/ /MP $(CXXFLAGS)
CXXFLAGS_NDEBUG = /MD /O2 /Ot /Gy /D NDEBUG
CXXFLAGS_DEBUG = /MDd /Od /Zi /D _DEBUG
LIB_LINK_FLAGS = /nologo /machine:$(XARCH)
tachyon_common.lib:
@cmd.exe /C if not exist obj mkdir obj
$(CXX) $(CXXFLAGS_NDEBUG) $(CXXFLAGS_COMMON) $(SOURCE_COMMON)
LIB $(LIB_LINK_FLAGS) obj/*.obj /OUT:$@
@cmd.exe /C if exist obj rmdir /S /Q obj
tachyon_common_debug.lib:
@cmd.exe /C if not exist obj mkdir obj
$(CXX) $(CXXFLAGS_DEBUG) $(CXXFLAGS_COMMON) $(SOURCE_COMMON)
LIB $(LIB_LINK_FLAGS) obj/*.obj /OUT:$@
@cmd.exe /C if exist obj rmdir /S /Q obj
build_serial: tachyon_common.lib
@$(MAKE) -f $(MAKEINC) SOURCE="src/trace.serial.cpp $(SOURCE) tachyon_common.lib" EXE=tachyon.serial.exe RCNAME=gui UI=$(UI) CXX="$(CXX)" CXXFLAGS="/GL $(CXXFLAGS)" XARCH=$(XARCH) build_one
build_serial_debug: tachyon_common_debug.lib
@$(MAKE) -f $(MAKEINC) SOURCE="src/trace.serial.cpp $(SOURCE) tachyon_common_debug.lib" EXE=tachyon.serial.exe RCNAME=gui UI=$(UI) DEBUG=_debug CXX="$(CXX)" CXXFLAGS=$(CXXFLAGS) XARCH=$(XARCH) build_one
run_serial:
-.\tachyon.serial.exe $(ARGS)
build_tbb: tachyon_common.lib
@$(MAKE) -f $(MAKEINC) SOURCE="src/trace.tbb.cpp $(SOURCE) tachyon_common.lib" EXE=tachyon.tbb.exe RCNAME=gui UI=$(UI) CXX="$(CXX)" CXXFLAGS="$(CXXFLAGS_TBB_NDEBUG)" LFLAGS="$(LIBS_TBB_NDEBUG)" XARCH=$(XARCH) build_one
build_tbb_debug: tachyon_common_debug.lib
@$(MAKE) -f $(MAKEINC) SOURCE="src/trace.tbb.cpp $(SOURCE) tachyon_common_debug.lib" EXE=tachyon.tbb.exe RCNAME=gui UI=$(UI) DEBUG=_debug CXX="$(CXX)" CXXFLAGS="$(CXXFLAGS_TBB_DEBUG)" LFLAGS="$(LIBS_TBB_DEBUG)" XARCH=$(XARCH) build_one
run_tbb:
-.\tachyon.tbb.exe $(ARGS)
build_tbb1d: tachyon_common.lib
@$(MAKE) -f $(MAKEINC) SOURCE="src/trace.tbb1d.cpp $(SOURCE) tachyon_common.lib" EXE=tachyon.tbb1d.exe RCNAME=gui UI=$(UI) CXX="$(CXX)" CXXFLAGS="$(CXXFLAGS_TBB_NDEBUG)" LFLAGS="$(LIBS_TBB_NDEBUG)" XARCH=$(XARCH) build_one
build_tbb1d_debug: tachyon_common_debug.lib
@$(MAKE) -f $(MAKEINC) SOURCE="src/trace.tbb1d.cpp $(SOURCE) tachyon_common_debug.lib" EXE=tachyon.tbb1d.exe RCNAME=gui UI=$(UI) DEBUG=_debug CXX="$(CXX)" CXXFLAGS="$(CXXFLAGS_TBB_DEBUG)" LFLAGS="$(LIBS_TBB_DEBUG)" XARCH=$(XARCH) build_one
run_tbb1d:
-.\tachyon.tbb1d.exe $(ARGS)
clean:
@cmd.exe /C del tachyon.* *.manifest *.obj *.lib msvs\gui.res *.?db
perf_build: tachyon_common.lib
@$(MAKE) -f $(MAKEINC) SOURCE="src/trace.tbb.cpp $(SOURCE) tachyon_common.lib" EXE=tachyon.tbb.exe RCNAME=gui UI=con CXX="$(CXX)" CXXFLAGS="$(CXXFLAGS_TBB_NDEBUG)" LFLAGS="$(LIBS_TBB_NDEBUG)" XARCH=$(XARCH) build_one
perf_run:
-.\tachyon.tbb.exe $(PERF_RUN_ARGS)
light_test:
-.\tachyon.tbb.exe $(LIGHT_ARGS)

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,104 @@
BEGIN_SCENE
OUTFILE /dev/null
RESOLUTION 512 512
VERBOSE 0
CAMERA
ZOOM 1.0
ASPECTRATIO 1.0
ANTIALIASING 1
RAYDEPTH 12
CENTER 0.0 0.0 -5.0
VIEWDIR 0.0 0.0 1.0
UPDIR 0.0 1.0 0.0
END_CAMERA
LIGHT
CENTER -5.0 0.0 -4.0
RAD 0.2
COLOR 1.0 0.1 0.0
LIGHT
CENTER 4.0 5.0 -4.0
RAD 0.2
COLOR 0.0 0.1 1.0
LIGHT
CENTER 4.0 1.5 3.0
RAD 0.2
COLOR 0.5 0.5 0.5
TRI
V0 0.0 -4.0 12.0
V1 4.0 -4.0 8.0
V2 -4.0 -4.0 8.0
TEXTURE
AMBIENT 0.1 DIFFUSE 0.2 SPECULAR 0.7 OPACITY 1.0
COLOR 1.0 1.0 1.0
TEXFUNC 0
SPHERE
CENTER 0.0 0.0 5.0
RAD 1.3
TEXTURE
AMBIENT 0.1 DIFFUSE 0.0 SPECULAR 0.9 OPACITY 1.0
COLOR 1.0 1.0 1.0
TEXFUNC 0
SPHERE
CENTER 1.0 0.0 4.3
RAD 0.8
TEXTURE
AMBIENT 0.1 DIFFUSE 0.9 SPECULAR 0.0 OPACITY 1.0
COLOR 0.3 0.3 1.0
TEXFUNC 3
CENTER 1.0 0.0 4.3
ROTATE 0. 0.0 0.0
SCALE 1.0 1.0 1.0
SPHERE
CENTER 0.0 2.0 8.0
RAD 1.0
TEXTURE
AMBIENT 0.1 DIFFUSE 0.9 SPECULAR 0.0 OPACITY 1.0
COLOR 1.0 0.0 1.0
TEXFUNC 4
CENTER 0.0 1.0 8.0
ROTATE 0. 0.0 0.0
SCALE 1.0 1.0 1.0
SPHERE
CENTER -1.0 -0.5 5.0
RAD 1.0
TEXTURE
AMBIENT 0.1 DIFFUSE 0.9 SPECULAR 0.0 OPACITY 1.0
COLOR 1.0 1.0 0.5
TEXFUNC 6
CENTER -1.0 -0.5 5.0
ROTATE 0. 0.0 0.0
SCALE 1.0 1.0 1.0
PLANE
CENTER 0.0 -5.0 0.0
NORMAL 0.0 1.0 0.0
TEXTURE
AMBIENT 0.1 DIFFUSE 0.9 SPECULAR 0.0 OPACITY 1.0
COLOR 1.0 1.0 1.0
TEXFUNC 1
CENTER 0.0 -5.0 0.0
ROTATE 0. 0.0 0.0
SCALE 1.0 1.0 1.0
PLANE
CENTER 0.0 0.0 15.0
NORMAL 0.0 0.0 -1.0
TEXTURE
AMBIENT 0.1 DIFFUSE 0.9 SPECULAR 0.0 OPACITY 1.0
COLOR 1.0 1.0 1.0
TEXFUNC 3
CENTER 0.0 0.0 15.0
ROTATE 0. 0.0 0.0
SCALE 1.0 1.0 1.0
END_SCENE

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,538 @@
BEGIN_SCENE
OUTFILE /dev/null
RESOLUTION 768 768
VERBOSE 0
CAMERA
ZOOM 1.0
ASPECTRATIO 1.0
ANTIALIASING 0
RAYDEPTH 4
CENTER 15.0 20.0 -50.0
VIEWDIR 0.0 0.0 1.0
UPDIR 0.0 1.0 0.0
END_CAMERA
LIGHT
CENTER 40.0 50.0 -40.0
RAD 0.2
COLOR 0.5 0.5 0.5
LIGHT
CENTER -40.0 20.0 -40.0
RAD 0.2
COLOR 0.5 0.5 0.5
TEXDEF O AMBIENT 0.1 DIFFUSE 0.9 SPECULAR 0.0 OPACITY 1.0
PHONG PLASTIC 0.5 PHONG_SIZE 24.8
COLOR 1.0 0.0 0.0 TEXFUNC 0
TEXALIAS OH O
TEXALIAS OD1 O
TEXALIAS OD2 O
TEXALIAS OE1 O
TEXALIAS OE2 O
TEXALIAS OG O
TEXALIAS OG1 O
TEXALIAS OG2 O
TEXALIAS OXT O
TEXDEF C AMBIENT 0.1 DIFFUSE 0.5 SPECULAR 0.0 OPACITY 1.0
PHONG PLASTIC 0.5 PHONG_SIZE 24.8
COLOR 0.5 0.5 0.5 TEXFUNC 0
TEXALIAS CA C
TEXALIAS CB C
TEXALIAS CD C
TEXALIAS CD1 C
TEXALIAS CD2 C
TEXALIAS CE C
TEXALIAS CE1 C
TEXALIAS CE2 C
TEXALIAS CG C
TEXALIAS CG1 C
TEXALIAS CG2 C
TEXALIAS CZ C
TEXDEF N AMBIENT 0.1 DIFFUSE 0.9 SPECULAR 0.0 OPACITY 1.0
PHONG PLASTIC 0.5 PHONG_SIZE 24.8
COLOR 0.5 0.5 1.0 TEXFUNC 0
TEXALIAS ND2 N
TEXALIAS NH1 N
TEXALIAS NH2 N
TEXALIAS NE N
TEXALIAS NE2 N
TEXALIAS NZ N
TEXDEF SD AMBIENT 0.1 DIFFUSE 0.9 SPECULAR 0.0 OPACITY 1.0
PHONG METAL 0.5 PHONG_SIZE 24.8
COLOR 1.0 1.0 1.0 TEXFUNC 0
TEXDEF SG AMBIENT 0.1 DIFFUSE 0.9 SPECULAR 0.0 OPACITY 1.0
PHONG PLASTIC 0.5 PHONG_SIZE 24.8
COLOR 1.0 1.0 1.0 TEXFUNC 0
SPHERE CENTER 26.465000 27.452000 -2.490000 RAD 1.0 N
SPHERE CENTER 25.497000 26.862000 -1.573000 RAD 1.0 CA
SPHERE CENTER 26.193001 26.179001 -0.437000 RAD 1.0 C
SPHERE CENTER 27.270000 25.549000 -0.624000 RAD 1.0 O
SPHERE CENTER 24.583000 25.804001 -2.239000 RAD 1.0 CB
SPHERE CENTER 25.091000 24.375000 -2.409000 RAD 1.0 CG
SPHERE CENTER 24.018999 23.427999 -2.996000 RAD 1.0 CD
SPHERE CENTER 23.591000 24.028000 -4.287000 RAD 1.0 NE
SPHERE CENTER 24.299000 23.972000 -5.389000 RAD 1.0 CZ
SPHERE CENTER 25.431999 23.261000 -5.440000 RAD 1.0 NH1
SPHERE CENTER 23.721001 24.372999 -6.467000 RAD 1.0 NH2
SPHERE CENTER 25.667000 26.396000 0.708000 RAD 1.0 N
SPHERE CENTER 26.222000 25.760000 1.891000 RAD 1.0 CA
SPHERE CENTER 26.207001 24.242001 1.830000 RAD 1.0 C
SPHERE CENTER 25.400000 23.576000 1.139000 RAD 1.0 O
SPHERE CENTER 25.260000 26.207001 3.033000 RAD 1.0 CB
SPHERE CENTER 24.511999 27.427999 2.493000 RAD 1.0 CG
SPHERE CENTER 24.606001 27.382000 0.978000 RAD 1.0 CD
SPHERE CENTER 27.170000 23.634001 2.462000 RAD 1.0 N
SPHERE CENTER 27.284000 22.163000 2.498000 RAD 1.0 CA
SPHERE CENTER 26.042999 21.506001 3.085000 RAD 1.0 C
SPHERE CENTER 25.752001 20.350000 2.705000 RAD 1.0 O
SPHERE CENTER 28.424999 21.747000 3.461000 RAD 1.0 CB
SPHERE CENTER 29.791000 21.886000 2.787000 RAD 1.0 CG
SPHERE CENTER 29.875000 22.104000 1.543000 RAD 1.0 OD1
SPHERE CENTER 30.806000 21.500999 3.431000 RAD 1.0 OD2
SPHERE CENTER 25.393999 22.184000 4.041000 RAD 1.0 N
SPHERE CENTER 24.172001 21.584999 4.618000 RAD 1.0 CA
SPHERE CENTER 23.009001 21.375000 3.624000 RAD 1.0 C
SPHERE CENTER 22.082001 20.603001 3.921000 RAD 1.0 O
SPHERE CENTER 23.691999 22.330999 5.862000 RAD 1.0 CB
SPHERE CENTER 23.191999 23.778999 5.639000 RAD 1.0 CG
SPHERE CENTER 21.961000 24.002001 5.060000 RAD 1.0 CD1
SPHERE CENTER 23.951000 24.841000 6.050000 RAD 1.0 CD2
SPHERE CENTER 21.497000 25.281000 4.869000 RAD 1.0 CE1
SPHERE CENTER 23.510000 26.124001 5.854000 RAD 1.0 CE2
SPHERE CENTER 22.277000 26.363001 5.249000 RAD 1.0 CZ
SPHERE CENTER 23.094999 22.004000 2.522000 RAD 1.0 N
SPHERE CENTER 22.106001 21.863001 1.467000 RAD 1.0 CA
SPHERE CENTER 22.191999 20.518000 0.830000 RAD 1.0 C
SPHERE CENTER 21.230000 20.068001 0.167000 RAD 1.0 O
SPHERE CENTER 22.358000 22.903999 0.371000 RAD 1.0 CB
SPHERE CENTER 22.145000 24.591999 0.888000 RAD 1.0 SG
SPHERE CENTER 23.326000 19.826000 1.008000 RAD 1.0 N
SPHERE CENTER 23.436001 18.459999 0.459000 RAD 1.0 CA
SPHERE CENTER 22.958000 17.365000 1.407000 RAD 1.0 C
SPHERE CENTER 22.938000 16.180000 0.999000 RAD 1.0 O
SPHERE CENTER 24.898001 18.084000 0.131000 RAD 1.0 CB
SPHERE CENTER 25.572001 19.129000 -0.776000 RAD 1.0 CG
SPHERE CENTER 27.037001 18.695000 -1.116000 RAD 1.0 CD1
SPHERE CENTER 24.791000 19.488001 -2.049000 RAD 1.0 CD2
SPHERE CENTER 22.545000 17.716000 2.628000 RAD 1.0 N
SPHERE CENTER 22.039000 16.646000 3.528000 RAD 1.0 CA
SPHERE CENTER 20.615999 16.285000 3.113000 RAD 1.0 C
SPHERE CENTER 19.860001 17.136000 2.576000 RAD 1.0 O
SPHERE CENTER 21.764000 17.216999 4.920000 RAD 1.0 CB
SPHERE CENTER 22.813999 18.035000 5.647000 RAD 1.0 CG
SPHERE CENTER 22.152000 18.707001 6.870000 RAD 1.0 CD
SPHERE CENTER 22.980000 19.100000 7.718000 RAD 1.0 OE1
SPHERE CENTER 21.086000 19.403999 6.779000 RAD 1.0 OE2
SPHERE CENTER 20.254000 15.031000 3.334000 RAD 1.0 N
SPHERE CENTER 18.892000 14.554000 3.034000 RAD 1.0 CA
SPHERE CENTER 17.954000 15.160000 4.079000 RAD 1.0 C
SPHERE CENTER 18.443001 15.606000 5.146000 RAD 1.0 O
SPHERE CENTER 18.910000 13.045000 3.274000 RAD 1.0 CB
SPHERE CENTER 20.226000 12.742000 4.021000 RAD 1.0 CG
SPHERE CENTER 21.107000 14.009000 3.934000 RAD 1.0 CD
SPHERE CENTER 16.681999 15.232000 3.767000 RAD 1.0 N
SPHERE CENTER 15.690000 15.852000 4.661000 RAD 1.0 CA
SPHERE CENTER 15.550000 15.006000 5.916000 RAD 1.0 C
SPHERE CENTER 15.693000 13.769000 5.836000 RAD 1.0 O
SPHERE CENTER 14.367000 15.707000 3.867000 RAD 1.0 CB
SPHERE CENTER 14.571000 14.716000 2.710000 RAD 1.0 CG
SPHERE CENTER 16.090000 14.597000 2.574000 RAD 1.0 CD
SPHERE CENTER 15.365000 15.630000 7.042000 RAD 1.0 N
SPHERE CENTER 15.310000 14.908000 8.298000 RAD 1.0 CA
SPHERE CENTER 13.953000 15.177000 8.952000 RAD 1.0 C
SPHERE CENTER 13.699000 16.320000 9.382000 RAD 1.0 O
SPHERE CENTER 16.532000 15.383000 9.122000 RAD 1.0 CB
SPHERE CENTER 16.608000 14.781000 10.525000 RAD 1.0 CG
SPHERE CENTER 17.132000 13.535000 10.707000 RAD 1.0 CD1
SPHERE CENTER 16.155001 15.523000 11.588000 RAD 1.0 CD2
SPHERE CENTER 17.216000 12.999000 11.982000 RAD 1.0 CE1
SPHERE CENTER 16.266001 14.985000 12.862000 RAD 1.0 CE2
SPHERE CENTER 16.808001 13.746000 13.047000 RAD 1.0 CZ
SPHERE CENTER 16.878000 13.192000 14.372000 RAD 1.0 OH
SPHERE CENTER 13.161000 14.146000 9.088000 RAD 1.0 N
SPHERE CENTER 11.802000 14.321000 9.642000 RAD 1.0 CA
SPHERE CENTER 11.855000 14.484000 11.146000 RAD 1.0 C
SPHERE CENTER 11.105000 15.314000 11.759000 RAD 1.0 O
SPHERE CENTER 10.963000 13.105000 9.273000 RAD 1.0 CB
SPHERE CENTER 10.706000 13.192000 7.854000 RAD 1.0 OG1
SPHERE CENTER 9.611000 13.152000 10.045000 RAD 1.0 CG2
SPHERE CENTER 12.789000 13.760000 11.726000 RAD 1.0 N
SPHERE CENTER 13.002000 13.922000 13.198000 RAD 1.0 CA
SPHERE CENTER 12.107000 12.944000 13.909000 RAD 1.0 C
SPHERE CENTER 11.333000 12.212000 13.239000 RAD 1.0 O
SPHERE CENTER 12.235000 12.905000 15.210000 RAD 1.0 N
SPHERE CENTER 11.516000 11.958000 16.066999 RAD 1.0 CA
SPHERE CENTER 10.094000 12.319000 16.468000 RAD 1.0 C
SPHERE CENTER 9.440000 11.442000 17.052000 RAD 1.0 O
SPHERE CENTER 12.272000 11.936000 17.370001 RAD 1.0 CB
SPHERE CENTER 13.164000 13.172000 17.399000 RAD 1.0 CG
SPHERE CENTER 13.281000 13.627000 15.925000 RAD 1.0 CD
SPHERE CENTER 9.629000 13.519000 16.214001 RAD 1.0 N
SPHERE CENTER 8.290000 13.980000 16.615999 RAD 1.0 CA
SPHERE CENTER 7.268000 13.720000 15.515000 RAD 1.0 C
SPHERE CENTER 7.672000 13.397000 14.387000 RAD 1.0 O
SPHERE CENTER 8.279000 15.441000 16.966999 RAD 1.0 CB
SPHERE CENTER 9.221000 15.735000 18.490000 RAD 1.0 SG
SPHERE CENTER 6.027000 13.680000 15.869000 RAD 1.0 N
SPHERE CENTER 5.005000 13.220000 14.945000 RAD 1.0 CA
SPHERE CENTER 3.964000 14.283000 14.630000 RAD 1.0 C
SPHERE CENTER 2.777000 13.949000 14.377000 RAD 1.0 O
SPHERE CENTER 4.310000 11.998000 15.592000 RAD 1.0 CB
SPHERE CENTER 5.273000 10.848000 15.913000 RAD 1.0 CG
SPHERE CENTER 5.781000 10.034000 14.702000 RAD 1.0 CD
SPHERE CENTER 6.855000 9.016000 15.126000 RAD 1.0 CE
SPHERE CENTER 7.357000 8.291000 13.953000 RAD 1.0 NZ
SPHERE CENTER 4.325000 15.549000 14.618000 RAD 1.0 N
SPHERE CENTER 3.513000 16.639999 14.122000 RAD 1.0 CA
SPHERE CENTER 3.561000 16.615000 12.586000 RAD 1.0 C
SPHERE CENTER 4.270000 15.752000 12.023000 RAD 1.0 O
SPHERE CENTER 3.984000 17.995001 14.670000 RAD 1.0 CB
SPHERE CENTER 2.781000 17.424999 11.943000 RAD 1.0 N
SPHERE CENTER 2.700000 17.355000 10.457000 RAD 1.0 CA
SPHERE CENTER 2.875000 18.731001 9.887000 RAD 1.0 C
SPHERE CENTER 1.878000 19.469999 9.653000 RAD 1.0 O
SPHERE CENTER 1.320000 16.787001 9.970000 RAD 1.0 CB
SPHERE CENTER 1.186000 15.339000 10.395000 RAD 1.0 CG
SPHERE CENTER -0.170000 14.751000 9.963000 RAD 1.0 CD
SPHERE CENTER -1.132000 15.455000 10.801000 RAD 1.0 NE
SPHERE CENTER -1.531000 14.913000 11.939000 RAD 1.0 CZ
SPHERE CENTER -1.172000 13.658000 12.165000 RAD 1.0 NH1
SPHERE CENTER -2.202000 15.647000 12.795000 RAD 1.0 NH2
SPHERE CENTER 4.154000 19.110001 9.817000 RAD 1.0 N
SPHERE CENTER 4.595000 20.444000 9.391000 RAD 1.0 CA
SPHERE CENTER 5.249000 20.388000 8.012000 RAD 1.0 C
SPHERE CENTER 6.193000 19.612000 7.834000 RAD 1.0 O
SPHERE CENTER 5.590000 20.988001 10.452000 RAD 1.0 CB
SPHERE CENTER 4.792000 21.062000 11.815000 RAD 1.0 CG1
SPHERE CENTER 5.985000 22.451000 10.085000 RAD 1.0 CG2
SPHERE CENTER 5.689000 21.535999 12.955000 RAD 1.0 CD1
SPHERE CENTER 4.586000 20.955999 7.035000 RAD 1.0 N
SPHERE CENTER 5.154000 20.879000 5.697000 RAD 1.0 CA
SPHERE CENTER 6.286000 21.912001 5.572000 RAD 1.0 C
SPHERE CENTER 6.156000 23.146000 5.785000 RAD 1.0 O
SPHERE CENTER 4.095000 21.205000 4.648000 RAD 1.0 CB
SPHERE CENTER 2.836000 20.316999 4.886000 RAD 1.0 CG1
SPHERE CENTER 4.655000 20.930000 3.250000 RAD 1.0 CG2
SPHERE CENTER 3.122000 18.813999 4.850000 RAD 1.0 CD1
SPHERE CENTER 7.451000 21.372000 5.297000 RAD 1.0 N
SPHERE CENTER 8.602000 22.257000 5.060000 RAD 1.0 CA
SPHERE CENTER 9.150000 21.950001 3.673000 RAD 1.0 C
SPHERE CENTER 8.840000 20.896000 3.088000 RAD 1.0 O
SPHERE CENTER 9.698000 21.896999 6.092000 RAD 1.0 CB
SPHERE CENTER 9.226000 22.299999 7.493000 RAD 1.0 CG
SPHERE CENTER 9.248000 23.850000 7.622000 RAD 1.0 CD
SPHERE CENTER 8.810000 24.311001 8.962000 RAD 1.0 NE
SPHERE CENTER 9.575000 24.336000 10.075000 RAD 1.0 CZ
SPHERE CENTER 10.888000 24.077000 10.044000 RAD 1.0 NH1
SPHERE CENTER 9.050000 24.893000 11.170000 RAD 1.0 NH2
SPHERE CENTER 10.178000 22.695000 3.318000 RAD 1.0 N
SPHERE CENTER 10.959000 22.444000 2.085000 RAD 1.0 CA
SPHERE CENTER 12.407000 22.010000 2.386000 RAD 1.0 C
SPHERE CENTER 12.987000 22.511999 3.378000 RAD 1.0 O
SPHERE CENTER 10.997000 23.770000 1.282000 RAD 1.0 CB
SPHERE CENTER 9.641000 24.038000 0.627000 RAD 1.0 CG
SPHERE CENTER 8.639000 24.591999 1.399000 RAD 1.0 CD1
SPHERE CENTER 9.451000 23.725000 -0.691000 RAD 1.0 CD2
SPHERE CENTER 7.403000 24.861000 0.831000 RAD 1.0 CE1
SPHERE CENTER 8.213000 23.993000 -1.249000 RAD 1.0 CE2
SPHERE CENTER 7.215000 24.576000 -0.494000 RAD 1.0 CZ
SPHERE CENTER 5.879000 24.768999 -1.060000 RAD 1.0 OH
SPHERE CENTER 12.977000 21.141001 1.535000 RAD 1.0 N
SPHERE CENTER 14.449000 20.892000 1.626000 RAD 1.0 CA
SPHERE CENTER 15.018000 21.045000 0.237000 RAD 1.0 C
SPHERE CENTER 14.250000 20.837000 -0.740000 RAD 1.0 O
SPHERE CENTER 14.664000 19.434999 2.142000 RAD 1.0 CB
SPHERE CENTER 14.283000 18.275999 1.191000 RAD 1.0 CG
SPHERE CENTER 15.290000 17.639000 0.506000 RAD 1.0 CD1
SPHERE CENTER 12.962000 17.907000 0.976000 RAD 1.0 CD2
SPHERE CENTER 14.981000 16.632000 -0.392000 RAD 1.0 CE1
SPHERE CENTER 12.638000 16.909000 0.061000 RAD 1.0 CE2
SPHERE CENTER 13.673000 16.261999 -0.626000 RAD 1.0 CZ
SPHERE CENTER 16.336000 21.281000 0.152000 RAD 1.0 N
SPHERE CENTER 16.948000 21.292000 -1.153000 RAD 1.0 CA
SPHERE CENTER 17.365000 19.888000 -1.542000 RAD 1.0 C
SPHERE CENTER 18.009001 19.184000 -0.744000 RAD 1.0 O
SPHERE CENTER 18.188000 22.194000 -1.071000 RAD 1.0 CB
SPHERE CENTER 18.906000 22.263000 -2.442000 RAD 1.0 CG
SPHERE CENTER 20.089001 21.621000 -2.663000 RAD 1.0 CD1
SPHERE CENTER 18.361000 23.033001 -3.436000 RAD 1.0 CD2
SPHERE CENTER 20.733000 21.778999 -3.896000 RAD 1.0 CE1
SPHERE CENTER 18.990999 23.184999 -4.662000 RAD 1.0 CE2
SPHERE CENTER 20.184999 22.562000 -4.864000 RAD 1.0 CZ
SPHERE CENTER 20.826000 22.768000 -6.115000 RAD 1.0 OH
SPHERE CENTER 16.913000 19.452999 -2.726000 RAD 1.0 N
SPHERE CENTER 17.295000 18.160000 -3.291000 RAD 1.0 CA
SPHERE CENTER 18.406000 18.332001 -4.341000 RAD 1.0 C
SPHERE CENTER 18.166000 18.843000 -5.464000 RAD 1.0 O
SPHERE CENTER 16.052000 17.558001 -3.946000 RAD 1.0 CB
SPHERE CENTER 16.354000 16.226999 -4.626000 RAD 1.0 CG
SPHERE CENTER 17.531000 15.754000 -4.725000 RAD 1.0 OD1
SPHERE CENTER 15.234000 15.549000 -4.870000 RAD 1.0 ND2
SPHERE CENTER 19.655001 18.124001 -3.871000 RAD 1.0 N
SPHERE CENTER 20.851000 18.420000 -4.681000 RAD 1.0 CA
SPHERE CENTER 20.920000 17.650000 -6.010000 RAD 1.0 C
SPHERE CENTER 21.385000 18.257000 -6.997000 RAD 1.0 O
SPHERE CENTER 22.112000 18.070999 -3.866000 RAD 1.0 CB
SPHERE CENTER 20.333000 16.480000 -6.081000 RAD 1.0 N
SPHERE CENTER 20.243999 15.784000 -7.383000 RAD 1.0 CA
SPHERE CENTER 19.287001 16.482000 -8.327000 RAD 1.0 C
SPHERE CENTER 19.478001 16.368999 -9.556000 RAD 1.0 O
SPHERE CENTER 19.732000 14.353000 -7.259000 RAD 1.0 CB
SPHERE CENTER 20.799999 13.485000 -6.626000 RAD 1.0 CG
SPHERE CENTER 20.299000 12.037000 -6.533000 RAD 1.0 CD
SPHERE CENTER 21.386999 11.067000 -6.033000 RAD 1.0 CE
SPHERE CENTER 21.820999 11.437000 -4.681000 RAD 1.0 NZ
SPHERE CENTER 18.212999 17.041000 -7.772000 RAD 1.0 N
SPHERE CENTER 17.181999 17.617001 -8.631000 RAD 1.0 CA
SPHERE CENTER 17.468000 19.070000 -8.921000 RAD 1.0 C
SPHERE CENTER 16.909000 19.707001 -9.863000 RAD 1.0 O
SPHERE CENTER 15.833000 17.423000 -7.901000 RAD 1.0 CB
SPHERE CENTER 18.299000 19.622000 -8.061000 RAD 1.0 N
SPHERE CENTER 18.625999 21.035999 -8.237000 RAD 1.0 CA
SPHERE CENTER 17.587999 22.051001 -7.738000 RAD 1.0 C
SPHERE CENTER 17.702000 23.257999 -8.056000 RAD 1.0 O
SPHERE CENTER 16.632000 21.566000 -6.970000 RAD 1.0 N
SPHERE CENTER 15.576000 22.431999 -6.478000 RAD 1.0 CA
SPHERE CENTER 14.947000 21.879999 -5.199000 RAD 1.0 C
SPHERE CENTER 15.304000 20.784000 -4.719000 RAD 1.0 O
SPHERE CENTER 14.553000 22.764999 -7.568000 RAD 1.0 CB
SPHERE CENTER 14.018000 21.514000 -8.283000 RAD 1.0 CG
SPHERE CENTER 13.211000 20.593000 -7.394000 RAD 1.0 CD1
SPHERE CENTER 13.189000 21.898001 -9.518000 RAD 1.0 CD2
SPHERE CENTER 14.114000 22.691999 -4.605000 RAD 1.0 N
SPHERE CENTER 13.591000 22.299999 -3.306000 RAD 1.0 CA
SPHERE CENTER 12.246000 21.612000 -3.398000 RAD 1.0 C
SPHERE CENTER 11.508000 21.862000 -4.381000 RAD 1.0 O
SPHERE CENTER 13.406000 23.628000 -2.540000 RAD 1.0 CB
SPHERE CENTER 14.977000 24.433001 -2.196000 RAD 1.0 SG
SPHERE CENTER 12.005000 20.672001 -2.530000 RAD 1.0 N
SPHERE CENTER 10.813000 19.820999 -2.569000 RAD 1.0 CA
SPHERE CENTER 10.208000 19.822001 -1.167000 RAD 1.0 C
SPHERE CENTER 10.918000 20.218000 -0.210000 RAD 1.0 O
SPHERE CENTER 11.110000 18.377001 -3.007000 RAD 1.0 CB
SPHERE CENTER 11.604000 18.464001 -4.496000 RAD 1.0 CG
SPHERE CENTER 12.041000 17.093000 -4.992000 RAD 1.0 CD
SPHERE CENTER 12.104000 16.884001 -6.223000 RAD 1.0 OE1
SPHERE CENTER 12.461000 16.246000 -4.115000 RAD 1.0 NE2
SPHERE CENTER 8.983000 19.459000 -1.072000 RAD 1.0 N
SPHERE CENTER 8.377000 19.427999 0.280000 RAD 1.0 CA
SPHERE CENTER 8.573000 18.100000 0.950000 RAD 1.0 C
SPHERE CENTER 8.785000 17.013000 0.347000 RAD 1.0 O
SPHERE CENTER 6.844000 19.700001 0.273000 RAD 1.0 CB
SPHERE CENTER 6.304000 18.825001 -0.706000 RAD 1.0 OG1
SPHERE CENTER 6.585000 21.149000 -0.177000 RAD 1.0 CG2
SPHERE CENTER 8.526000 18.187000 2.280000 RAD 1.0 N
SPHERE CENTER 8.582000 16.999001 3.087000 RAD 1.0 CA
SPHERE CENTER 7.801000 17.273001 4.382000 RAD 1.0 C
SPHERE CENTER 7.554000 18.469000 4.665000 RAD 1.0 O
SPHERE CENTER 10.066000 16.503000 3.399000 RAD 1.0 CB
SPHERE CENTER 10.840000 17.323999 4.462000 RAD 1.0 CG
SPHERE CENTER 11.188000 16.711000 5.670000 RAD 1.0 CD1
SPHERE CENTER 11.224000 18.618999 4.188000 RAD 1.0 CD2
SPHERE CENTER 11.912000 17.452999 6.617000 RAD 1.0 CE1
SPHERE CENTER 11.948000 19.333000 5.129000 RAD 1.0 CE2
SPHERE CENTER 12.277000 18.763000 6.344000 RAD 1.0 CZ
SPHERE CENTER 7.455000 16.219999 5.116000 RAD 1.0 N
SPHERE CENTER 6.756000 16.414000 6.390000 RAD 1.0 CA
SPHERE CENTER 7.798000 16.358999 7.491000 RAD 1.0 C
SPHERE CENTER 8.422000 15.296000 7.692000 RAD 1.0 O
SPHERE CENTER 5.716000 15.281000 6.557000 RAD 1.0 CB
SPHERE CENTER 4.973000 15.432000 7.882000 RAD 1.0 CG1
SPHERE CENTER 4.667000 15.326000 5.371000 RAD 1.0 CG2
SPHERE CENTER 7.953000 17.509001 8.095000 RAD 1.0 N
SPHERE CENTER 8.816000 17.659000 9.286000 RAD 1.0 CA
SPHERE CENTER 7.941000 17.294001 10.498000 RAD 1.0 C
SPHERE CENTER 6.818000 17.832001 10.661000 RAD 1.0 O
SPHERE CENTER 9.260000 19.136000 9.274000 RAD 1.0 CB
SPHERE CENTER 10.066000 19.506001 10.540000 RAD 1.0 CG
SPHERE CENTER 11.058000 18.667999 11.032000 RAD 1.0 CD1
SPHERE CENTER 9.728000 20.677999 11.181000 RAD 1.0 CD2
SPHERE CENTER 11.713000 19.021999 12.217000 RAD 1.0 CE1
SPHERE CENTER 10.401000 21.042000 12.346000 RAD 1.0 CE2
SPHERE CENTER 11.371000 20.211000 12.851000 RAD 1.0 CZ
SPHERE CENTER 12.040000 20.579000 14.049000 RAD 1.0 OH
SPHERE CENTER 8.505000 16.504999 11.400000 RAD 1.0 N
SPHERE CENTER 7.774000 16.076000 12.622000 RAD 1.0 CA
SPHERE CENTER 7.696000 17.099001 13.728000 RAD 1.0 C
SPHERE CENTER 6.978000 16.834999 14.718000 RAD 1.0 O
SPHERE CENTER 8.385000 18.202000 13.646000 RAD 1.0 N
SPHERE CENTER 8.275000 19.365999 14.533000 RAD 1.0 CA
SPHERE CENTER 9.338000 19.430000 15.620000 RAD 1.0 C
SPHERE CENTER 9.309000 20.379999 16.415001 RAD 1.0 O
SPHERE CENTER 10.317000 18.555000 15.610000 RAD 1.0 N
SPHERE CENTER 11.453000 18.707001 16.541000 RAD 1.0 CA
SPHERE CENTER 12.763000 18.232000 15.950000 RAD 1.0 C
SPHERE CENTER 12.753000 17.224001 15.201000 RAD 1.0 O
SPHERE CENTER 11.179000 18.055000 17.937000 RAD 1.0 CB
SPHERE CENTER 11.154000 16.283001 17.922001 RAD 1.0 SG
SPHERE CENTER 13.828000 18.788000 16.528999 RAD 1.0 N
SPHERE CENTER 15.222000 18.386999 16.261999 RAD 1.0 CA
SPHERE CENTER 15.644000 18.605000 14.798000 RAD 1.0 C
SPHERE CENTER 16.306000 17.708000 14.224000 RAD 1.0 O
SPHERE CENTER 15.486000 16.941000 16.719000 RAD 1.0 CB
SPHERE CENTER 14.949000 16.624001 18.146999 RAD 1.0 CG
SPHERE CENTER 15.484000 17.593000 19.195000 RAD 1.0 CD
SPHERE CENTER 15.081000 17.068001 20.497000 RAD 1.0 NE
SPHERE CENTER 15.268000 17.830999 21.573999 RAD 1.0 CZ
SPHERE CENTER 15.870000 19.020000 21.452999 RAD 1.0 NH1
SPHERE CENTER 14.930000 17.320999 22.753000 RAD 1.0 NH2
SPHERE CENTER 15.154000 19.670000 14.180000 RAD 1.0 N
SPHERE CENTER 15.461000 19.893999 12.733000 RAD 1.0 CA
SPHERE CENTER 16.969000 19.924000 12.482000 RAD 1.0 C
SPHERE CENTER 17.752001 20.431000 13.327000 RAD 1.0 O
SPHERE CENTER 14.918000 21.275000 12.366000 RAD 1.0 CB
SPHERE CENTER 17.282000 19.622000 11.271000 RAD 1.0 N
SPHERE CENTER 18.584999 19.886999 10.687000 RAD 1.0 CA
SPHERE CENTER 18.461000 21.087000 9.753000 RAD 1.0 C
SPHERE CENTER 17.371000 21.708000 9.790000 RAD 1.0 O
SPHERE CENTER 18.961000 18.612000 9.934000 RAD 1.0 CB
SPHERE CENTER 19.486000 17.514999 10.843000 RAD 1.0 CG
SPHERE CENTER 20.042999 16.424999 9.926000 RAD 1.0 CD
SPHERE CENTER 20.782000 15.386000 10.779000 RAD 1.0 CE
SPHERE CENTER 20.985001 14.137000 10.021000 RAD 1.0 NZ
SPHERE CENTER 19.577000 21.643999 9.215000 RAD 1.0 N
SPHERE CENTER 19.570999 22.903000 8.543000 RAD 1.0 CA
SPHERE CENTER 18.898001 22.847000 7.144000 RAD 1.0 C
SPHERE CENTER 18.476000 23.930000 6.690000 RAD 1.0 O
SPHERE CENTER 20.981001 23.469999 8.429000 RAD 1.0 CB
SPHERE CENTER 21.461000 24.047001 9.786000 RAD 1.0 CG
SPHERE CENTER 22.614000 25.047001 9.608000 RAD 1.0 CD
SPHERE CENTER 22.118999 26.403999 9.384000 RAD 1.0 NE
SPHERE CENTER 22.948000 27.426001 9.370000 RAD 1.0 CZ
SPHERE CENTER 24.253000 27.187000 9.415000 RAD 1.0 NH1
SPHERE CENTER 22.472000 28.634001 9.297000 RAD 1.0 NH2
SPHERE CENTER 18.870001 21.715000 6.474000 RAD 1.0 N
SPHERE CENTER 18.209999 21.712999 5.169000 RAD 1.0 CA
SPHERE CENTER 16.671000 21.559000 5.372000 RAD 1.0 C
SPHERE CENTER 16.068001 20.466000 5.197000 RAD 1.0 O
SPHERE CENTER 18.745001 20.506001 4.379000 RAD 1.0 CB
SPHERE CENTER 18.295000 20.591999 2.909000 RAD 1.0 CG
SPHERE CENTER 17.721001 21.629000 2.499000 RAD 1.0 OD1
SPHERE CENTER 18.664000 19.563999 2.134000 RAD 1.0 ND2
SPHERE CENTER 16.097000 22.643000 5.820000 RAD 1.0 N
SPHERE CENTER 14.676000 22.662001 6.349000 RAD 1.0 CA
SPHERE CENTER 14.157000 24.101999 6.384000 RAD 1.0 C
SPHERE CENTER 14.715000 24.959000 7.120000 RAD 1.0 O
SPHERE CENTER 14.577000 21.951000 7.736000 RAD 1.0 CB
SPHERE CENTER 13.128000 21.861000 8.301000 RAD 1.0 CG
SPHERE CENTER 12.432000 22.889000 8.208000 RAD 1.0 OD1
SPHERE CENTER 12.975000 21.035000 9.288000 RAD 1.0 ND2
SPHERE CENTER 13.324000 24.438000 5.381000 RAD 1.0 N
SPHERE CENTER 12.918000 25.816999 5.120000 RAD 1.0 CA
SPHERE CENTER 11.388000 25.961000 5.164000 RAD 1.0 C
SPHERE CENTER 10.669000 24.966000 4.915000 RAD 1.0 O
SPHERE CENTER 13.372000 26.372999 3.741000 RAD 1.0 CB
SPHERE CENTER 14.913000 26.191999 3.701000 RAD 1.0 CG
SPHERE CENTER 15.492000 25.002001 3.268000 RAD 1.0 CD1
SPHERE CENTER 15.705000 27.252001 4.053000 RAD 1.0 CD2
SPHERE CENTER 16.877001 24.881001 3.132000 RAD 1.0 CE1
SPHERE CENTER 17.108999 27.125999 3.941000 RAD 1.0 CE2
SPHERE CENTER 17.659000 25.957001 3.487000 RAD 1.0 CZ
SPHERE CENTER 10.949000 27.146999 5.460000 RAD 1.0 N
SPHERE CENTER 9.480000 27.343000 5.498000 RAD 1.0 CA
SPHERE CENTER 8.875000 27.670000 4.157000 RAD 1.0 C
SPHERE CENTER 7.634000 27.622999 4.057000 RAD 1.0 O
SPHERE CENTER 9.045000 28.475000 6.433000 RAD 1.0 CB
SPHERE CENTER 9.258000 27.945999 7.875000 RAD 1.0 CG
SPHERE CENTER 9.119000 29.052000 8.948000 RAD 1.0 CD
SPHERE CENTER 10.025000 28.736000 10.167000 RAD 1.0 CE
SPHERE CENTER 9.826000 29.728001 11.231000 RAD 1.0 NZ
SPHERE CENTER 9.687000 27.909000 3.152000 RAD 1.0 N
SPHERE CENTER 9.124000 28.167999 1.840000 RAD 1.0 CA
SPHERE CENTER 10.108000 27.719000 0.765000 RAD 1.0 C
SPHERE CENTER 11.332000 27.660000 1.047000 RAD 1.0 O
SPHERE CENTER 8.778000 29.648001 1.642000 RAD 1.0 CB
SPHERE CENTER 10.000000 30.391001 1.484000 RAD 1.0 OG
SPHERE CENTER 9.604000 27.471001 -0.422000 RAD 1.0 N
SPHERE CENTER 10.526000 27.160999 -1.512000 RAD 1.0 CA
SPHERE CENTER 11.423000 28.346001 -1.863000 RAD 1.0 C
SPHERE CENTER 12.634000 28.115000 -2.136000 RAD 1.0 O
SPHERE CENTER 9.782000 26.679001 -2.783000 RAD 1.0 CB
SPHERE CENTER 10.966000 29.570000 -1.682000 RAD 1.0 N
SPHERE CENTER 11.751000 30.764000 -1.998000 RAD 1.0 CA
SPHERE CENTER 12.900000 30.964001 -1.040000 RAD 1.0 C
SPHERE CENTER 14.032000 31.282000 -1.463000 RAD 1.0 O
SPHERE CENTER 10.871000 32.021999 -2.024000 RAD 1.0 CB
SPHERE CENTER 9.868000 32.069000 -3.200000 RAD 1.0 CG
SPHERE CENTER 8.525000 31.417000 -2.847000 RAD 1.0 CD
SPHERE CENTER 7.573000 31.562000 -3.638000 RAD 1.0 OE1
SPHERE CENTER 8.368000 30.636999 -1.865000 RAD 1.0 OE2
SPHERE CENTER 12.658000 30.686001 0.225000 RAD 1.0 N
SPHERE CENTER 13.804000 30.775000 1.163000 RAD 1.0 CA
SPHERE CENTER 14.824000 29.667000 0.941000 RAD 1.0 C
SPHERE CENTER 16.058001 29.903999 1.049000 RAD 1.0 O
SPHERE CENTER 13.347000 30.500000 2.601000 RAD 1.0 CB
SPHERE CENTER 12.813000 31.775999 3.236000 RAD 1.0 CG
SPHERE CENTER 12.716000 32.875000 2.613000 RAD 1.0 OD1
SPHERE CENTER 12.096000 31.598000 4.247000 RAD 1.0 OD2
SPHERE CENTER 14.305000 28.478001 0.644000 RAD 1.0 N
SPHERE CENTER 15.128000 27.301001 0.379000 RAD 1.0 CA
SPHERE CENTER 16.006001 27.523001 -0.852000 RAD 1.0 C
SPHERE CENTER 17.247999 27.267000 -0.809000 RAD 1.0 O
SPHERE CENTER 14.238000 26.045000 0.259000 RAD 1.0 CB
SPHERE CENTER 15.047000 24.530001 -0.176000 RAD 1.0 SG
SPHERE CENTER 15.384000 28.062000 -1.870000 RAD 1.0 N
SPHERE CENTER 16.191999 28.302000 -3.048000 RAD 1.0 CA
SPHERE CENTER 17.171000 29.452999 -2.841000 RAD 1.0 C
SPHERE CENTER 18.246000 29.474001 -3.490000 RAD 1.0 O
SPHERE CENTER 15.267000 28.570999 -4.266000 RAD 1.0 CB
SPHERE CENTER 14.634000 27.261000 -4.708000 RAD 1.0 CG
SPHERE CENTER 15.759000 25.962000 -5.253000 RAD 1.0 SD
SPHERE CENTER 16.306999 26.625000 -6.805000 RAD 1.0 CE
SPHERE CENTER 16.775999 30.469999 -2.099000 RAD 1.0 N
SPHERE CENTER 17.652000 31.617001 -1.869000 RAD 1.0 CA
SPHERE CENTER 18.910000 31.125999 -1.141000 RAD 1.0 C
SPHERE CENTER 20.049999 31.469999 -1.556000 RAD 1.0 O
SPHERE CENTER 16.934000 32.595001 -0.930000 RAD 1.0 CB
SPHERE CENTER 17.721001 33.839001 -0.540000 RAD 1.0 CG
SPHERE CENTER 16.740999 35.039001 -0.291000 RAD 1.0 CD
SPHERE CENTER 15.472000 34.667999 0.404000 RAD 1.0 NE
SPHERE CENTER 14.256000 34.889999 -0.074000 RAD 1.0 CZ
SPHERE CENTER 13.983000 35.465000 -1.233000 RAD 1.0 NH1
SPHERE CENTER 13.260000 34.542999 0.660000 RAD 1.0 NH2
SPHERE CENTER 18.726999 30.198999 -0.237000 RAD 1.0 N
SPHERE CENTER 19.889999 29.693001 0.496000 RAD 1.0 CA
SPHERE CENTER 20.636999 28.649000 -0.297000 RAD 1.0 C
SPHERE CENTER 21.871000 28.686001 -0.287000 RAD 1.0 O
SPHERE CENTER 19.416000 29.106001 1.823000 RAD 1.0 CB
SPHERE CENTER 18.643999 30.132000 2.537000 RAD 1.0 OG1
SPHERE CENTER 20.615999 28.506001 2.662000 RAD 1.0 CG2
SPHERE CENTER 19.988001 27.747000 -0.961000 RAD 1.0 N
SPHERE CENTER 20.669001 26.563999 -1.471000 RAD 1.0 CA
SPHERE CENTER 20.773001 26.534000 -2.963000 RAD 1.0 C
SPHERE CENTER 21.341000 25.552999 -3.498000 RAD 1.0 O
SPHERE CENTER 19.955999 25.260000 -1.056000 RAD 1.0 CB
SPHERE CENTER 20.128000 24.914000 0.713000 RAD 1.0 SG
SPHERE CENTER 20.132000 27.441999 -3.608000 RAD 1.0 N
SPHERE CENTER 19.987000 27.268000 -5.071000 RAD 1.0 CA
SPHERE CENTER 21.257000 27.575001 -5.849000 RAD 1.0 C
SPHERE CENTER 21.386000 27.129000 -7.018000 RAD 1.0 O
SPHERE CENTER 22.225000 28.049999 -5.113000 RAD 1.0 N
SPHERE CENTER 23.639000 28.131001 -5.505000 RAD 1.0 CA
SPHERE CENTER 23.886999 29.393000 -6.316000 RAD 1.0 C
SPHERE CENTER 22.948999 30.065001 -6.822000 RAD 1.0 O
SPHERE CENTER 25.146000 29.681000 -6.493000 RAD 1.0 N
SPHERE CENTER 25.617001 30.840000 -7.256000 RAD 1.0 CA
SPHERE CENTER 25.247999 30.735001 -8.729000 RAD 1.0 C
SPHERE CENTER 24.962000 31.791000 -9.369000 RAD 1.0 O
SPHERE CENTER 27.160000 30.980000 -7.146000 RAD 1.0 CB
SPHERE CENTER 24.919001 29.594000 -9.172000 RAD 1.0 OXT
PLANE
CENTER 0.0 -25.0 0.0
NORMAL 0.0 1.0 0.0
TEXTURE
AMBIENT 0.1 DIFFUSE 0.9 SPECULAR 0.0 OPACITY 1.0
COLOR 1.0 1.0 1.0
TEXFUNC 0
END_SCENE

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

View File

@@ -0,0 +1,90 @@
// Microsoft Visual C++ generated resource script.
//
#include "resource.h"
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#define APSTUDIO_HIDDEN_SYMBOLS
#include "windows.h"
#undef APSTUDIO_HIDDEN_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// English (U.S.) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
#ifdef _WIN32
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)
#endif //_WIN32
/////////////////////////////////////////////////////////////////////////////
//
// Icon
//
// Icon with lowest ID value placed first to ensure application icon
// remains consistent on all systems.
IDI_GUI ICON "gui.ico"
IDI_SMALL ICON "small.ico"
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE
BEGIN
"resource.h\0"
END
2 TEXTINCLUDE
BEGIN
"#define APSTUDIO_HIDDEN_SYMBOLS\r\n"
"#include ""windows.h""\r\n"
"#undef APSTUDIO_HIDDEN_SYMBOLS\r\n"
"\0"
END
3 TEXTINCLUDE
BEGIN
"\r\n"
"\0"
END
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// String Table
//
STRINGTABLE
BEGIN
IDS_APP_TITLE "gui"
IDC_GUI "GUI"
END
#endif // English (U.S.) resources
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED

View File

@@ -0,0 +1,24 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#define IDC_MYICON 2
#define IDD_GUI 102
#define IDS_APP_TITLE 103
#define IDI_GUI 107
#define IDI_SMALL 108
#define IDC_GUI 109
#define IDR_MAINFRAME 128
#define IDC_STATIC -1

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

View File

@@ -0,0 +1,15 @@
<Application
x:Class="tbbTachyon.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:tbbTachyon">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Common/StandardStyles.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>

View File

@@ -0,0 +1,50 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include "DirectXPage.xaml.h"
using namespace tbbTachyon;
using namespace Platform;
using namespace Windows::ApplicationModel;
using namespace Windows::ApplicationModel::Activation;
using namespace Windows::Foundation;
using namespace Windows::Foundation::Collections;
using namespace Windows::Storage;
using namespace Windows::UI::Xaml;
using namespace Windows::UI::Xaml::Controls;
using namespace Windows::UI::Xaml::Controls::Primitives;
using namespace Windows::UI::Xaml::Data;
using namespace Windows::UI::Xaml::Input;
using namespace Windows::UI::Xaml::Interop;
using namespace Windows::UI::Xaml::Media;
using namespace Windows::UI::Xaml::Navigation;
#include "src/tachyon_video.h"
App::App()
{
InitializeComponent();
}
void App::OnLaunched(Windows::ApplicationModel::Activation::LaunchActivatedEventArgs^ pArgs)
{
m_directXPage = ref new DirectXPage();
// Place the frame in the current Window and ensure that it is active
Window::Current->Content = m_directXPage;
Window::Current->Activate();
}

View File

@@ -0,0 +1,37 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#pragma once
#include "App.g.h"
#include "DirectXPage.xaml.h"
namespace tbbTachyon
{
/// <summary>
/// Provides application-specific behavior to supplement the default Application class.
/// </summary>
ref class App sealed
{
public:
App();
virtual void OnLaunched(Windows::ApplicationModel::Activation::LaunchActivatedEventArgs^ pArgs) override;
private:
DirectXPage^ m_directXPage;
};
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 141 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.2 KiB

View File

@@ -0,0 +1,409 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include "pch.h"
#include "DirectXBase.h"
#include <windows.ui.xaml.media.dxinterop.h>
#include <math.h>
using namespace Microsoft::WRL;
using namespace Windows::UI::Core;
using namespace Windows::UI::Xaml::Controls;
using namespace Windows::Foundation;
using namespace Windows::Graphics::Display;
using namespace D2D1;
// Constructor.
DirectXBase::DirectXBase() :
m_dpi(-1.0f)
{
}
// Initialize the DirectX resources required to run.
void DirectXBase::Initialize(CoreWindow^ window, SwapChainBackgroundPanel^ panel, float dpi)
{
m_window = window;
m_panel = panel;
CreateDeviceIndependentResources();
CreateDeviceResources();
SetDpi(dpi);
}
// These are the resources required independent of the device.
void DirectXBase::CreateDeviceIndependentResources()
{
D2D1_FACTORY_OPTIONS options;
ZeroMemory(&options, sizeof(D2D1_FACTORY_OPTIONS));
#if defined(_DEBUG)
// If the project is in a debug build, enable Direct2D debugging via SDK Layers
// TODO: investigate resource leaks reported by a debug version of a device.
// options.debugLevel = D2D1_DEBUG_LEVEL_INFORMATION;
#endif
DX::ThrowIfFailed(
D2D1CreateFactory(
D2D1_FACTORY_TYPE_SINGLE_THREADED,
__uuidof(ID2D1Factory1),
&options,
&m_d2dFactory
)
);
DX::ThrowIfFailed(
DWriteCreateFactory(
DWRITE_FACTORY_TYPE_SHARED,
__uuidof(IDWriteFactory),
&m_dwriteFactory
)
);
DX::ThrowIfFailed(
CoCreateInstance(
CLSID_WICImagingFactory,
nullptr,
CLSCTX_INPROC_SERVER,
IID_PPV_ARGS(&m_wicFactory)
)
);
}
// These are the resources that depend on the device.
void DirectXBase::CreateDeviceResources()
{
// This flag adds support for surfaces with a different color channel ordering than the API default.
// It is recommended usage, and is required for compatibility with Direct2D.
UINT creationFlags = D3D11_CREATE_DEVICE_BGRA_SUPPORT;
ComPtr<IDXGIDevice> dxgiDevice;
#if defined(_DEBUG)
// If the project is in a debug build, enable debugging via SDK Layers with this flag.
creationFlags |= D3D11_CREATE_DEVICE_DEBUG;
#endif
// This array defines the set of DirectX hardware feature levels this app will support.
// Note the ordering should be preserved.
// Don't forget to declare your application's minimum required feature level in its
// description. All applications are assumed to support 9.1 unless otherwise stated.
D3D_FEATURE_LEVEL featureLevels[] =
{
D3D_FEATURE_LEVEL_11_1,
D3D_FEATURE_LEVEL_11_0,
D3D_FEATURE_LEVEL_10_1,
D3D_FEATURE_LEVEL_10_0,
D3D_FEATURE_LEVEL_9_3,
D3D_FEATURE_LEVEL_9_2,
D3D_FEATURE_LEVEL_9_1
};
// Create the DX11 API device object, and get a corresponding context.
ComPtr<ID3D11Device> device;
ComPtr<ID3D11DeviceContext> context;
DX::ThrowIfFailed(
D3D11CreateDevice(
nullptr, // specify null to use the default adapter
D3D_DRIVER_TYPE_HARDWARE,
0, // leave as 0 unless software device
creationFlags, // optionally set debug and Direct2D compatibility flags
featureLevels, // list of feature levels this app can support
ARRAYSIZE(featureLevels), // number of entries in above list
D3D11_SDK_VERSION, // always set this to D3D11_SDK_VERSION for Metro style apps
&device, // returns the Direct3D device created
&m_featureLevel, // returns feature level of device created
&context // returns the device immediate context
)
);
// Get the DirectX11.1 device by QI off the DirectX11 one.
DX::ThrowIfFailed(
device.As(&m_d3dDevice)
);
// And get the corresponding device context in the same way.
DX::ThrowIfFailed(
context.As(&m_d3dContext)
);
// Obtain the underlying DXGI device of the Direct3D11.1 device.
DX::ThrowIfFailed(
m_d3dDevice.As(&dxgiDevice)
);
// Obtain the Direct2D device for 2-D rendering.
DX::ThrowIfFailed(
m_d2dFactory->CreateDevice(dxgiDevice.Get(), &m_d2dDevice)
);
// And get its corresponding device context object.
DX::ThrowIfFailed(
m_d2dDevice->CreateDeviceContext(
D2D1_DEVICE_CONTEXT_OPTIONS_NONE,
&m_d2dContext
)
);
// Release the swap chain (if it exists) as it will be incompatible with the new device.
m_swapChain = nullptr;
}
// Helps track the DPI in the helper class.
// This is called in the dpiChanged event handler in the view class.
void DirectXBase::SetDpi(float dpi)
{
if (dpi != m_dpi)
{
// Save the DPI of this display in our class.
m_dpi = dpi;
// Update Direct2D's stored DPI.
m_d2dContext->SetDpi(m_dpi, m_dpi);
// Often a DPI change implies a window size change. In some cases Windows will issues
// both a size changed event and a DPI changed event. In this case, the resulting bounds
// will not change, and the window resize code will only be executed once.
UpdateForWindowSizeChange();
}
}
// This routine is called in the event handler for the view SizeChanged event.
void DirectXBase::UpdateForWindowSizeChange()
{
// Only handle window size changed if there is no pending DPI change.
if (m_dpi != DisplayInformation::GetForCurrentView()->LogicalDpi)
return;
if (m_window->Bounds.Width != m_windowBounds.Width ||
m_window->Bounds.Height != m_windowBounds.Height)
{
m_d2dContext->SetTarget(nullptr);
m_d2dTargetBitmap = nullptr;
m_renderTargetView = nullptr;
m_depthStencilView = nullptr;
CreateWindowSizeDependentResources();
}
}
// Allocate all memory resources that change on a window SizeChanged event.
void DirectXBase::CreateWindowSizeDependentResources()
{
// Store the window bounds so the next time we get a SizeChanged event we can
// avoid rebuilding everything if the size is identical.
m_windowBounds = m_window->Bounds;
// Calculate the necessary swap chain and render target size in pixels.
m_renderTargetSize.Width = ConvertDipsToPixels(m_windowBounds.Width);
m_renderTargetSize.Height = ConvertDipsToPixels(m_windowBounds.Height);
// If the swap chain already exists, resize it.
if (m_swapChain != nullptr)
{
DX::ThrowIfFailed(
m_swapChain->ResizeBuffers(
2,
static_cast<UINT>(m_renderTargetSize.Width),
static_cast<UINT>(m_renderTargetSize.Height),
DXGI_FORMAT_B8G8R8A8_UNORM,
0
)
);
}
// Otherwise, create a new one.
else
{
// Allocate a descriptor.
DXGI_SWAP_CHAIN_DESC1 swapChainDesc = {0};
swapChainDesc.Width = static_cast<UINT>(m_renderTargetSize.Width); // Match the size of the windowm.
swapChainDesc.Height = static_cast<UINT>(m_renderTargetSize.Height);
swapChainDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM; // This is the most common swapchain format.
swapChainDesc.Stereo = false;
swapChainDesc.SampleDesc.Count = 1; // Don't use multi-sampling.
swapChainDesc.SampleDesc.Quality = 0;
swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
swapChainDesc.BufferCount = 2; // Use double buffering to enable flip.
swapChainDesc.Scaling = DXGI_SCALING_STRETCH;
swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL; // All Metro style apps must use this SwapEffect.
swapChainDesc.Flags = 0;
// Once the desired swap chain description is configured, it must be created on the same adapter as our D3D Device.
// First, retrieve the underlying DXGI Device from the D3D Device.
ComPtr<IDXGIDevice1> dxgiDevice;
DX::ThrowIfFailed(
m_d3dDevice.As(&dxgiDevice)
);
// Identify the physical adapter (GPU or card) this device is running on.
ComPtr<IDXGIAdapter> dxgiAdapter;
DX::ThrowIfFailed(
dxgiDevice->GetAdapter(&dxgiAdapter)
);
// And obtain the factory object that created it.
ComPtr<IDXGIFactory2> dxgiFactory;
DX::ThrowIfFailed(
dxgiAdapter->GetParent(IID_PPV_ARGS(&dxgiFactory))
);
// Create the swap chain and then associate it with the SwapChainBackgroundPanel.
DX::ThrowIfFailed(
dxgiFactory->CreateSwapChainForComposition(
m_d3dDevice.Get(),
&swapChainDesc,
nullptr,
&m_swapChain
)
);
ComPtr<ISwapChainBackgroundPanelNative> panelNative;
DX::ThrowIfFailed(
reinterpret_cast<IUnknown*>(m_panel)->QueryInterface(IID_PPV_ARGS(&panelNative))
);
DX::ThrowIfFailed(
panelNative->SetSwapChain(m_swapChain.Get())
);
// Ensure that DXGI does not queue more than one frame at a time. This both reduces
// latency and ensures that the application will only render after each VSync, minimizing
// power consumption.
DX::ThrowIfFailed(
dxgiDevice->SetMaximumFrameLatency(1)
);
}
// Obtain the backbuffer for this window which will be the final 3D rendertarget.
ComPtr<ID3D11Texture2D> backBuffer;
DX::ThrowIfFailed(
m_swapChain->GetBuffer(0, IID_PPV_ARGS(&backBuffer))
);
// Create a view interface on the rendertarget to use on bind.
DX::ThrowIfFailed(
m_d3dDevice->CreateRenderTargetView(
backBuffer.Get(),
nullptr,
&m_renderTargetView
)
);
// Create a descriptor for the depth/stencil buffer.
CD3D11_TEXTURE2D_DESC depthStencilDesc(
DXGI_FORMAT_D24_UNORM_S8_UINT,
static_cast<UINT>(m_renderTargetSize.Width),
static_cast<UINT>(m_renderTargetSize.Height),
1,
1,
D3D11_BIND_DEPTH_STENCIL
);
// Allocate a 2-D surface as the depth/stencil buffer.
ComPtr<ID3D11Texture2D> depthStencil;
DX::ThrowIfFailed(
m_d3dDevice->CreateTexture2D(
&depthStencilDesc,
nullptr,
&depthStencil
)
);
// Create a DepthStencil view on this surface to use on bind.
CD3D11_DEPTH_STENCIL_VIEW_DESC depthStencilViewDesc(D3D11_DSV_DIMENSION_TEXTURE2D);
DX::ThrowIfFailed(
m_d3dDevice->CreateDepthStencilView(
depthStencil.Get(),
&depthStencilViewDesc,
&m_depthStencilView
)
);
// Create a viewport descriptor of the full window size.
CD3D11_VIEWPORT viewport(
0.0f,
0.0f,
m_renderTargetSize.Width,
m_renderTargetSize.Height
);
// Set the current viewport using the descriptor.
m_d3dContext->RSSetViewports(1, &viewport);
// Now we set up the Direct2D render target bitmap linked to the swapchain.
// Whenever we render to this bitmap, it will be directly rendered to the
// swapchain associated with the window.
D2D1_BITMAP_PROPERTIES1 bitmapProperties =
BitmapProperties1(
D2D1_BITMAP_OPTIONS_TARGET | D2D1_BITMAP_OPTIONS_CANNOT_DRAW,
PixelFormat(DXGI_FORMAT_B8G8R8A8_UNORM, D2D1_ALPHA_MODE_PREMULTIPLIED),
m_dpi,
m_dpi
);
// Direct2D needs the DXGI version of the backbuffer surface pointer.
ComPtr<IDXGISurface> dxgiBackBuffer;
DX::ThrowIfFailed(
m_swapChain->GetBuffer(0, IID_PPV_ARGS(&dxgiBackBuffer))
);
// Get a D2D surface from the DXGI back buffer to use as the D2D render target.
DX::ThrowIfFailed(
m_d2dContext->CreateBitmapFromDxgiSurface(
dxgiBackBuffer.Get(),
&bitmapProperties,
&m_d2dTargetBitmap
)
);
// So now we can set the Direct2D render target.
m_d2dContext->SetTarget(m_d2dTargetBitmap.Get());
// Set D2D text anti-alias mode to Grayscale to ensure proper rendering of text on intermediate surfaces.
m_d2dContext->SetTextAntialiasMode(D2D1_TEXT_ANTIALIAS_MODE_GRAYSCALE);
}
// Method to deliver the final image to the display.
void DirectXBase::Present()
{
// The application may optionally specify "dirty" or "scroll" rects to improve efficiency
// in certain scenarios.
DXGI_PRESENT_PARAMETERS parameters = {0};
parameters.DirtyRectsCount = 0;
parameters.pDirtyRects = nullptr;
parameters.pScrollRect = nullptr;
parameters.pScrollOffset = nullptr;
// The first argument instructs DXGI to block until VSync, putting the application
// to sleep until the next VSync. This ensures we don't waste any cycles rendering
// frames that will never be displayed to the screen.
HRESULT hr = m_swapChain->Present1(1, 0, &parameters);
// If the device was removed either by a disconnect or a driver upgrade, we
// must completely reinitialize the renderer.
if (hr == DXGI_ERROR_DEVICE_REMOVED || hr == DXGI_ERROR_DEVICE_RESET)
{
Initialize(m_window.Get(), m_panel, m_dpi);
}
else
{
DX::ThrowIfFailed(hr);
}
}
// Method to convert a length in device-independent pixels (DIPs) to a length in physical pixels.
float DirectXBase::ConvertDipsToPixels(float dips)
{
static const float dipsPerInch = 96.0f;
return floor(dips * m_dpi / dipsPerInch + 0.5f); // Round to nearest integer.
}

View File

@@ -0,0 +1,88 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#pragma once
#include <wrl/client.h>
#include <d3d11_1.h>
#include <d2d1_1.h>
#include <d2d1effects.h>
#include <dwrite_1.h>
#include <wincodec.h>
#include "App.xaml.h"
#include <agile.h>
#pragma warning (disable: 4449)
// Helper utilities to make DirectX APIs work with exceptions
namespace DX
{
inline void ThrowIfFailed(HRESULT hr)
{
if (FAILED(hr))
{
// Set a breakpoint on this line to catch DirectX API errors
throw Platform::Exception::CreateException(hr);
}
}
}
// Helper class that initializes DirectX APIs
ref class DirectXBase abstract
{
internal:
DirectXBase();
public:
virtual void Initialize(Windows::UI::Core::CoreWindow^ window, Windows::UI::Xaml::Controls::SwapChainBackgroundPanel^ panel, float dpi);
virtual void CreateDeviceIndependentResources();
virtual void CreateDeviceResources();
virtual void SetDpi(float dpi);
virtual void CreateWindowSizeDependentResources();
virtual void UpdateForWindowSizeChange();
virtual void Render() = 0;
virtual void Present();
virtual float ConvertDipsToPixels(float dips);
protected private:
Platform::Agile<Windows::UI::Core::CoreWindow> m_window;
Windows::UI::Xaml::Controls::SwapChainBackgroundPanel^ m_panel;
// Direct2D Objects
Microsoft::WRL::ComPtr<ID2D1Factory1> m_d2dFactory;
Microsoft::WRL::ComPtr<ID2D1Device> m_d2dDevice;
Microsoft::WRL::ComPtr<ID2D1DeviceContext> m_d2dContext;
Microsoft::WRL::ComPtr<ID2D1Bitmap1> m_d2dTargetBitmap;
// DirectWrite & Windows Imaging Component Objects
Microsoft::WRL::ComPtr<IDWriteFactory1> m_dwriteFactory;
Microsoft::WRL::ComPtr<IWICImagingFactory2> m_wicFactory;
// Direct3D Objects
Microsoft::WRL::ComPtr<ID3D11Device1> m_d3dDevice;
Microsoft::WRL::ComPtr<ID3D11DeviceContext1> m_d3dContext;
Microsoft::WRL::ComPtr<IDXGISwapChain1> m_swapChain;
Microsoft::WRL::ComPtr<ID3D11RenderTargetView> m_renderTargetView;
Microsoft::WRL::ComPtr<ID3D11DepthStencilView> m_depthStencilView;
D3D_FEATURE_LEVEL m_featureLevel;
Windows::Foundation::Size m_renderTargetSize;
Windows::Foundation::Rect m_windowBounds;
float m_dpi;
};
#pragma warning (default: 4449)

View File

@@ -0,0 +1,31 @@
<SwapChainBackgroundPanel
x:Class="tbbTachyon.DirectXPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:tbbTachyon"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
>
<SwapChainBackgroundPanel.RowDefinitions>
<RowDefinition Height="15*"/>
<RowDefinition Height="17*"/>
</SwapChainBackgroundPanel.RowDefinitions>
<Page Grid.RowSpan="2" Background="Black" MinHeight="100" MaxHeight="100">
<Page.BottomAppBar>
<AppBar Padding="10,0,10,0">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="100" />
<ColumnDefinition Width="100" />
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" x:Name="NumberOfThreadsTextBlock" Text="Number Of Threads: Auto" TextAlignment="Center" TextWrapping="Wrap" Height="54" FontSize="20" VerticalAlignment="Top" HorizontalAlignment="Center"/>
<Slider Grid.Column="0" x:Name="ThreadsSlider" Minimum="0" Maximum="16" TickFrequency="1" TickPlacement="Outside" ValueChanged="ThreadsSliderValueChanged" Height="37" StepFrequency="1" IsThumbToolTipEnabled="False" />
<Button Grid.Column="1" x:Name="ThreadsApply" Style="{StaticResource YesAppBarButtonStyle}" Tag="Apply this number of threads" AutomationProperties.Name="Apply" Click="ThreadsApply_Click" HorizontalAlignment="Right" Visibility="Collapsed"/>
<Button Grid.Column="2" x:Name="Exit" Style="{StaticResource NoAppBarButtonStyle}" Tag="Exit" Click="Exit_Click" AutomationProperties.Name="Exit" HorizontalAlignment="Right" />
</Grid>
</AppBar>
</Page.BottomAppBar>
</Page>
</SwapChainBackgroundPanel>

View File

@@ -0,0 +1,128 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include "pch.h"
#include "DirectXPage.xaml.h"
using namespace tbbTachyon;
using namespace Platform;
using namespace Windows::Foundation;
using namespace Windows::Foundation::Collections;
using namespace Windows::UI::Input;
using namespace Windows::UI::Core;
using namespace Windows::UI::Xaml;
using namespace Windows::UI::Xaml::Controls;
using namespace Windows::UI::Xaml::Controls::Primitives;
using namespace Windows::UI::Xaml::Data;
using namespace Windows::UI::Xaml::Input;
using namespace Windows::UI::Xaml::Media;
using namespace Windows::UI::Xaml::Navigation;
using namespace Windows::Graphics::Display;
#include "src/tachyon_video.h"
extern int volatile global_number_of_threads;
extern volatile bool global_isCancelled;
#pragma intrinsic(_BitScanReverse)
static int log2( unsigned int x ) {
DWORD i;
_BitScanReverse(&i,(DWORD)x);
return (int)i;
}
const unsigned interval_step_power = 1;
const unsigned num_interval_steps = 1 << (interval_step_power+1);
DirectXPage::DirectXPage() :
m_renderNeeded(true)
{
InitializeComponent();
m_renderer = ref new tbbTachyonRenderer();
m_renderer->Initialize(
Window::Current->CoreWindow,
this,
DisplayInformation::GetForCurrentView()->LogicalDpi
);
m_eventToken = CompositionTarget::Rendering::add(ref new EventHandler<Object^>(this, &DirectXPage::OnRendering));
int num_threads = 2*utility::get_default_num_threads();
// The thread slider has geometric sequence with several intermediate steps for each interval between 2^N and 2^(N+1).
// The nearest (from below) the power of 2.
int i_base = int(log2(num_threads));
int base = 1 << i_base;
// The step size for the current interval.
int step = base / num_interval_steps;
// The number of steps inside the interval.
int i_step = (num_threads-base)/step;
ThreadsSlider->Maximum = (i_base-interval_step_power)*num_interval_steps + i_step;
global_number_of_threads = m_number_of_threads = utility::get_default_num_threads();
}
DirectXPage::~DirectXPage()
{
}
void DirectXPage::OnRendering(Platform::Object^ sender, Platform::Object^ args)
{
if (m_renderNeeded){
m_renderer->Render();
m_renderer->Present();
m_renderNeeded = true;
}
}
void tbbTachyon::DirectXPage::ThreadsApply_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
if (global_number_of_threads != m_number_of_threads){
global_number_of_threads = m_number_of_threads;
global_isCancelled = true;
video->running = false;
m_renderNeeded = true;
ThreadsApply->Visibility=Windows::UI::Xaml::Visibility::Collapsed;
}
}
void tbbTachyon::DirectXPage::Exit_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
m_renderNeeded = false;
Application::Current->Exit();
}
void tbbTachyon::DirectXPage::ThreadsSliderValueChanged(Platform::Object^ sender, Windows::UI::Xaml::Controls::Primitives::RangeBaseValueChangedEventArgs^ e)
{
int pos = (int) e->NewValue;
// The nearest (from below) the power of 2.
int base = pos<num_interval_steps ? 0 : 1 << (pos/num_interval_steps+interval_step_power);
// The step size for the current interval.
int step = max(1,base/num_interval_steps);
m_number_of_threads = base + (pos%num_interval_steps)*step;
if (m_number_of_threads == 0) m_number_of_threads = utility::get_default_num_threads();
NumberOfThreadsTextBlock->Text="Number Of Threads: " + (m_number_of_threads == utility::get_default_num_threads()? "Auto": m_number_of_threads.ToString());
if (global_number_of_threads != m_number_of_threads){
ThreadsApply->Visibility=Windows::UI::Xaml::Visibility::Visible;
}else{
ThreadsApply->Visibility=Windows::UI::Xaml::Visibility::Collapsed;
}
}

View File

@@ -0,0 +1,44 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#pragma once
#include "DirectXPage.g.h"
#include "tbbTachyonRenderer.h"
namespace tbbTachyon
{
[Windows::Foundation::Metadata::WebHostHidden]
public ref class DirectXPage sealed
{
public:
DirectXPage();
private:
~DirectXPage();
void OnRendering(Object^ sender, Object^ args);
Windows::Foundation::EventRegistrationToken m_eventToken;
tbbTachyonRenderer^ m_renderer;
bool m_renderNeeded;
int m_number_of_threads;
void ThreadsSliderValueChanged(Platform::Object^ sender, Windows::UI::Xaml::Controls::Primitives::RangeBaseValueChangedEventArgs^ e);
void ThreadsApply_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
void Exit_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
};
}

View File

@@ -0,0 +1,49 @@
<?xml version="1.0" encoding="utf-8"?>
<Package
xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10"
xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest"
xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
IgnorableNamespaces="uap mp">
<Identity
Name="551ef478-a6dc-40b3-a3ff-10052625a781"
Publisher="CN=Administrator"
Version="1.0.0.0" />
<mp:PhoneIdentity PhoneProductId="551ef478-a6dc-40b3-a3ff-10052625a781" PhonePublisherId="00000000-0000-0000-0000-000000000000"/>
<Properties>
<DisplayName>tbbTachyon</DisplayName>
<PublisherDisplayName>Administrator</PublisherDisplayName>
<Logo>Assets\StoreLogo.png</Logo>
</Properties>
<Dependencies>
<TargetDeviceFamily Name="Windows.Universal" MinVersion="10.0.0.0" MaxVersionTested="10.0.0.0" />
</Dependencies>
<Resources>
<Resource Language="x-generate"/>
</Resources>
<Applications>
<Application Id="App"
Executable="$targetnametoken$.exe"
EntryPoint="tbbTachyon.App">
<uap:VisualElements
DisplayName="tbbTachyon"
Square150x150Logo="Assets\Square150x150Logo.png"
Square44x44Logo="Assets\Square44x44Logo.png"
Description="tbbTachyon"
BackgroundColor="transparent">
<uap:DefaultTile Wide310x150Logo="Assets\Wide310x150Logo.png"/>
<uap:SplashScreen Image="Assets\SplashScreen.png" />
</uap:VisualElements>
</Application>
</Applications>
<Capabilities>
<Capability Name="internetClient" />
</Capabilities>
</Package>

View File

@@ -0,0 +1,70 @@
@echo on
REM
REM Copyright (c) 2005-2020 Intel Corporation
REM
REM Licensed under the Apache License, Version 2.0 (the "License");
REM you may not use this file except in compliance with the License.
REM You may obtain a copy of the License at
REM
REM http://www.apache.org/licenses/LICENSE-2.0
REM
REM Unless required by applicable law or agreed to in writing, software
REM distributed under the License is distributed on an "AS IS" BASIS,
REM WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
REM See the License for the specific language governing permissions and
REM limitations under the License.
REM
:: Getting parameters
:: Architecture
if ("%1") == ("") goto error0
:: Release/Debug
if ("%2") == ("") goto error0
:: Output directory
if (%3) == ("") goto error0
set arch=%1
if ("%2") == ("debug") set postfix=_debug
set output_dir="%3"
if ("%4") == ("") set dat_file="%output_dir%\..\..\dat\balls.dat"
:: Actually we can set install root by ourselves
if ("%TBBROOT%") == ("") set TBBROOT=%~dp0..\..\..\..\..\
:: Getting vs folders ordered from oldest to newest, so we end with newest available version
if ("%VS140COMNTOOLS%") NEQ ("") set vc_dir=vc14_uwp
:: To use Microsoft* Visual Studio* 2017 IDE, make sure the variable VS150COMNTOOLS is set in your IDE instance.
:: If it is not, try running Microsoft Visual Studio 2017 from Microsoft* Developer Command Prompt* for VS 2017.
:: For details, see https://developercommunity.visualstudio.com/content/problem/730/vs154-env-var-vs150comntools-missing-from-build-sy.html
if ("%VS150COMNTOOLS%") NEQ ("") set vc_dir=vc14_uwp
:: The same comment also applies to Microsoft Visual Studio 2019 and variable VS160COMNTOOLS
if ("%VS160COMNTOOLS%") NEQ ("") set vc_dir=vc14_uwp
echo Using %vc_dir% libraries
if exist "%TBBROOT%\bin\%arch%\%vc_dir%\tbb%postfix%.dll" set interim_path=bin\%arch%
if exist "%TBBROOT%..\redist\%arch%\tbb\%vc_dir%\tbb%postfix%.dll" set interim_path=..\redist\%arch%\tbb
if exist "%TBBROOT%\lib\%arch%\%vc_dir%\tbb%postfix%.lib" set interim_lib_path=lib\%arch%
if ("%interim_path%") == ("") goto error1
if ("%interim_lib_path%") == ("") goto error1
:: We know everything we wanted and there are no errors
:: Copying binaries
copy "%TBBROOT%\%interim_path%\%vc_dir%\tbb%postfix%.dll" "%output_dir%"
copy "%TBBROOT%\%interim_path%\%vc_dir%\tbb%postfix%.pdb" "%output_dir%"
copy "%TBBROOT%\%interim_path%\%vc_dir%\tbbmalloc%postfix%.dll" "%output_dir%"
copy "%TBBROOT%\%interim_path%\%vc_dir%\tbbmalloc%postfix%.pdb" "%output_dir%"
copy "%TBBROOT%\%interim_lib_path%\%vc_dir%\tbb%postfix%.lib" "%output_dir%"
:: Copying DAT-file
echo Using DAT-file %dat_file%
if exist %dat_file% copy %dat_file% "%output_dir%\Assets\balls.dat"
goto end
:error0
echo Custom build script usage: %0 [ia32 or intel64] [release or debug] [output dir] [dat-file]
exit /B 1
:error1
echo Could not determine path to Intel TBB libraries
exit /B 1
:end
exit /B 0

View File

@@ -0,0 +1,25 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#pragma once
#include <wrl/client.h>
#include <d3d11_1.h>
#include <d2d1_1.h>
#include <d2d1effects.h>
#include <dwrite_1.h>
#include <wincodec.h>
#include "App.xaml.h"

View File

@@ -0,0 +1,185 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include "pch.h"
#include "tbbTachyonRenderer.h"
#include <DirectXMath.h>
#include <process.h>
#include <thread>
#include "../../src/tachyon_video.h"
using namespace Microsoft::WRL;
using namespace Windows::Foundation;
using namespace Windows::Foundation::Collections;
using namespace Windows::UI::Core;
using namespace DirectX;
tbbTachyonRenderer::tbbTachyonRenderer() :
m_renderNeeded(true)
{
}
tbbTachyonRenderer::~tbbTachyonRenderer()
{
}
void tbbTachyonRenderer::CreateDeviceIndependentResources()
{
DirectXBase::CreateDeviceIndependentResources();
DX::ThrowIfFailed(
m_dwriteFactory->CreateTextFormat(
L"Segoe UI",
nullptr,
DWRITE_FONT_WEIGHT_NORMAL,
DWRITE_FONT_STYLE_NORMAL,
DWRITE_FONT_STRETCH_NORMAL,
32.0f,
L"en-US",
&m_textFormat
)
);
DX::ThrowIfFailed(
m_textFormat->SetTextAlignment(DWRITE_TEXT_ALIGNMENT_LEADING)
);
}
unsigned int __stdcall example_main(void*);
float g_ratiox, g_ratioy;
extern unsigned int *g_pImg;
extern int g_sizex, g_sizey;
extern int global_xsize, global_ysize;
extern int volatile global_number_of_threads;
extern volatile long global_startTime;
extern volatile long global_elapsedTime;
#define SHOW_TEXT 1
void tbbTachyonRenderer::CreateDeviceResources()
{
DirectXBase::CreateDeviceResources();
DX::ThrowIfFailed(
m_d2dContext->CreateSolidColorBrush(
D2D1::ColorF(D2D1::ColorF::Green),
&m_Brush
)
);
D2D1_BITMAP_PROPERTIES1 properties = D2D1::BitmapProperties1(
D2D1_BITMAP_OPTIONS_TARGET,
D2D1::PixelFormat(
DXGI_FORMAT_R8G8B8A8_UNORM,
D2D1_ALPHA_MODE_IGNORE
)
);
//Setting manual rendering size
global_xsize = 800;
global_ysize = int(global_xsize/m_window->Bounds.Width*m_window->Bounds.Height);
D2D1_SIZE_U opacityBitmapSize = D2D1::SizeU(global_xsize, global_ysize);
DX::ThrowIfFailed(
m_d2dContext->CreateBitmap(
opacityBitmapSize,
(BYTE*)g_pImg,
sizeof(unsigned int)*g_sizex,
&properties,
&m_opacityBitmap
)
);
m_d2dContext->SetTarget(m_opacityBitmap.Get());
m_d2dContext->BeginDraw();
m_d2dContext->Clear(D2D1::ColorF(D2D1::ColorF::Black, 0.0f));
DX::ThrowIfFailed(
m_d2dContext->EndDraw()
);
std::thread* thread_tmp=new std::thread(example_main, (void*)NULL);
}
void tbbTachyonRenderer::CreateWindowSizeDependentResources()
{
DirectXBase::CreateWindowSizeDependentResources();
}
void tbbTachyonRenderer::Render()
{
D2D1_SIZE_F size = m_d2dContext->GetSize();
#if SHOW_TEXT
if (video && video->running)
global_elapsedTime=(long)(time(NULL)-global_startTime);
Platform::String^ text= "Running in " +
(global_number_of_threads == utility::get_default_num_threads()? "all hardware threads: ":
global_number_of_threads.ToString() + (global_number_of_threads==1?" thread: ":" threads: ")) +
global_elapsedTime.ToString() + (global_elapsedTime>1?" seconds":" second");
g_ratiox=float(size.width/1024.0);
g_ratioy=float(size.height/512.0);
DX::ThrowIfFailed(
m_dwriteFactory->CreateTextLayout(
text->Data(),
text->Length(),
m_textFormat.Get(),
1000, // maxWidth
1000, // maxHeight
&m_textLayout
)
);
m_textLayout->GetMetrics(&m_textMetrics);
#endif
m_d2dContext->BeginDraw();
if(g_pImg)m_opacityBitmap->CopyFromMemory( NULL,(BYTE*)g_pImg, sizeof(unsigned int)*g_sizex );
m_d2dContext->DrawBitmap( m_opacityBitmap.Get(), D2D1::RectF(0,0,size.width,size.height) );
#if SHOW_TEXT
m_d2dContext->DrawTextLayout(
D2D1::Point2F(0.0f, 0.0f),
m_textLayout.Get(),
m_Brush.Get(),
D2D1_DRAW_TEXT_OPTIONS_CLIP
);
#endif
HRESULT hr = m_d2dContext->EndDraw();
if (hr == D2DERR_RECREATE_TARGET){
m_d2dContext->SetTarget(nullptr);
m_d2dTargetBitmap = nullptr;
CreateWindowSizeDependentResources();
}else{
DX::ThrowIfFailed(hr);
}
m_renderNeeded = false;
}

View File

@@ -0,0 +1,42 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#pragma once
#include <wrl.h>
#include "DirectXBase.h"
ref class tbbTachyonRenderer sealed : public DirectXBase
{
public:
tbbTachyonRenderer();
virtual void CreateDeviceIndependentResources() override;
virtual void CreateDeviceResources() override;
virtual void CreateWindowSizeDependentResources() override;
virtual void Render() override;
void Update(float timeTotal, float timeDelta);
void UpdateView(Windows::Foundation::Point deltaViewPosition);
private:
Microsoft::WRL::ComPtr<ID2D1SolidColorBrush> m_Brush;
Microsoft::WRL::ComPtr<IDWriteTextFormat> m_textFormat;
Microsoft::WRL::ComPtr<ID2D1Bitmap1> m_opacityBitmap;
Microsoft::WRL::ComPtr<IDWriteTextLayout> m_textLayout;
DWRITE_TEXT_METRICS m_textMetrics;
bool m_renderNeeded;
~tbbTachyonRenderer();
};

View File

@@ -0,0 +1,572 @@
<!DOCTYPE html>
<html xmlns:mso="urn:schemas-microsoft-com:office:office" xmlns:msdt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882">
<head>
<meta charset="UTF-8">
<style>
::selection {
background: #b7ffb7;
}
::-moz-selection {
background: #b7ffb7;
}
body {
font-family: Arial, Helvetica, sans-serif;
font-size: 16px;
width: 800px;
margin: 0 auto;
}
#banner {
/* Div for banner */
float:left;
margin: 0px;
margin-bottom: 10px;
width: 100%;
background-color: #0071C5;
z-index: 0;
}
#banner .logo {
/* Apply to logo in banner. Add as class to image tag. */
float: left;
margin-right: 20px;
margin-left: 20px;
margin-top: 15px;
padding-bottom: 5px;
}
h1 {
text-align: center;
font-size: 36px;
}
h1.title {
/* Add as class to H1 in banner */
font-family: "Intel Clear", Verdana, Arial, sans-serif;
font-weight:normal;
color: #FFFFFF;
font-size: 170%;
margin-right: 40px;
margin-left: 40px;
padding-right: 20px;
text-indent: 20px;
}
.h3-alike {
display:inline;
font-size: 1.17em;
font-weight: bold;
color: #0071C5;
}
h3 {
font-size: 1.17em;
font-weight: bold;
color: #0071C5;
}
.h4-alike {
display:inline;
font-size: 1.05em;
font-weight: bold;
}
pre {
font-family: "Consolas", Monaco, monospace;
font-size:small;
background: #fafafa;
margin: 0;
padding-left:20px;
}
#footer {
font-size: small;
}
code {
font-family: "Consolas", Monaco, monospace;
}
.code-block
{
padding-left:20px;
}
.changes {
margin: 1em 0;
}
.changes input:active {
position: relative;
top: 1px;
}
.changes input:hover:after {
padding-left: 16px;
font-size: 10px;
content: 'More';
}
.changes input:checked:hover:after {
content: 'Less';
}
.changes input + .show-hide {
display: none;
}
.changes input:checked + .show-hide {
display: block;
}
ul {
margin: 0;
padding: 0.5em 0 0.5em 2.5em;
}
ul li {
margin-bottom: 3px;
}
ul li:last-child {
margin-bottom: 0;
}
.disc {
list-style-type:disc
}
.circ {
list-style-type:circle
}
.single {
padding: 0 0.5em;
}
/* ------------------------------------------------- */
/* Table styles */
table{
margin-bottom:5pt;
border-collapse:collapse;
margin-left:0px;
margin-top:0.3em;
font-size:10pt;
}
tr{
vertical-align:top;
}
th,
th h3{
padding:4px;
text-align:left;
background-color:#0071C5;
font-weight:bold;
margin-top:1px;
margin-bottom:0;
color:#FFFFFF;
font-size:10pt;
vertical-align:middle;
}
th{
border:1px #dddddd solid;
padding-top:2px;
padding-bottom:0px;
padding-right:3px;
padding-left:3px;
}
td{
border:1px #dddddd solid;
vertical-align:top;
font-size:100%;
text-align:left;
margin-bottom:0;
}
td,
td p{
margin-top:0;
margin-left:0;
text-align:left;
font-size:inherit;
line-height:120%;
}
td p{
margin-bottom:0;
padding-top:5px;
padding-bottom:5px;
padding-right:5px;
padding-left:1px;
}
.noborder{
border:0px none;
}
.noborder1stcol{
border:0px none;
padding-left:0pt;
}
td ol{
font-size:inherit;
margin-left:28px;
}
td ul{
font-size:inherit;
margin-left:24px;
}
.DefListTbl{
width:90%;
margin-left:-3pt;
}
.syntaxdiagramtbl{
margin-left:-3pt;
}
.sdtbl{
}
.sdrow{
}
.sdtblp{
border:0px none;
font-size:inherit;
line-height:120%;
margin-bottom:0;
padding-bottom:0px;
padding-top:5px;
padding-left:0px;
padding-right:5px;
vertical-align:top;
}
.idepara, .ide_para{
border:0px none;
font-size:inherit;
line-height:120%;
margin-bottom:0;
padding-bottom:0px;
padding-top:5px;
padding-left:0px;
padding-right:5px;
vertical-align:top;
}
.specs {
border-collapse:collapse;
}
.specs td, .specs th {
font-size: 14px;
}
.specs td {
border: 1px solid black;
}
.specs td td, .specs td th {
border: none;
}
.specs td, .specs td td, .specs td th {
padding: 0 0.2em 0.2em;
text-align: center;
}
.specs td tr:last-child td,
.specs td tr:last-child th {
padding: 0 0.2em;
}
.serial-time {
}
.modified-time {
width: 6.5em;
}
.compiler {
}
.comp-opt {
}
.sys-specs {
width: 18em;
}
.note {
font-size:small;
font-style: italic;
}
</style>
<title>Intel&reg; Threading Building Blocks. Tachyon sample</title>
</head>
<body>
<div id="banner">
<img class="logo" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEMAAAAsCAYAAAA+aAX8AAAAAXNSR0IArs4c6QAAAARnQU1BAACx
jwv8YQUAAAAJcEhZcwAALiIAAC4iAari3ZIAAAAZdEVYdFNvZnR3YXJlAEFkb2JlIEltYWdlUmVh
ZHlxyWU8AAAIN0lEQVRoQ+WaCaxdUxSGW2ouatZWaVS15nkqkZhSVERQglLEPCam1BCixhqqCKUS
NIiYpxhqHmouIeaY5ylFzA/v1fev8+/j3N5737v3vtf3buNP/uy9/7X2Ovuse4a997m9mgltbW2L
wRHwcHgFfAx+AH+GCb/BT2fNmvUk5ZXwYOrrOsTcCU5CJ74pPBJeA5+Bn8LfOLmagf/f8Af4NrwD
ngg3wdTHh2pOMMB1Gejx8AE4M85mNqD/A7+D78GXkXQFTIMPwUfhdPg6/AxWTRw29b8QruPD9zwY
zPrwHPi2xxmg3QrfgDfD05BGU24EB1HvC3s7REXgtwDsDzeEY+Ak+AJsUfwE2sJdcBN37V4whiU4
+KGUM2JEBtpzUInZEa5g9y4FcYfAo+GLPmwOND2HFrXrnAUHWgnq0vzDB2+Bt0H9coPs1m3gmNvD
ZyITBu234Jp26XoQfCC80sfTAXVv7wOXskuPgnHoSvnTw9P49MDdyOauAQEXhWdC4Vd4ARxmc1OB
cW0Gv3U+lJDvKFa0ufMg4GXwR3gs7J57sRNoaWnR2+znLB2RkKds6jwItvbckIQiGO+eTkSby71t
qh100qtsUCJxmmpSw5i2gWebR1jWm2047T1gf0vyfViJEKi/TtHua7wMdNJs8U/zDzjUpqYA47k4
O704wY+kUZ2P+glQc5ldac9j323sF1cH2EB6h8BxYZdbRDeDOJ16UBJiHDFuMMdYbhjEGA8DxJ4h
jXIemmMpz6ccqbZ1JUlT/3SrHC+9XeB0MjzV9RHqKFAXVg2nBkH/lxxO8aZYbhjEKEuGQH1BuCKc
z1IAN61jAtiut1wZ+ByIkwa6r9t6ZmhSFZw9eL0gxiMw4SLLDYMYFZNRDbhpcpgwzXI5MOqSEvKM
Ue8D+xU4r/Xe+C8HB1ThkhFgNqAXk6FVqyZuA1LcItBXQd+WUvf6YMslwFZvMs7KvMP/SculwKa3
hfYPPsZpfsvS9QD9PRHbcOmUC9J+H2qfoRJ/0MHgFhHIQC8mQ8twxZ0Ji099vSGegn/TP0BdD/Db
Ycn0nna9yZiceQcetFwKDE/4oNtZCtDeXHoC7dWlU1Uyvs7U6sBHJ7FaBAPU82TYJUAzFnCU+1mq
COyfwGLi6k3G05l34BrL/wFxjA/0mKUcaNqBKiJODHclQ3sLCVqZprfEvVCLtThhiskRDFAvXhnv
QPlfi5uW7ytTL14Nr0Bd1pfDXy1Lv93h6koGLstCLR/SuPJ5SQBBD8hPZATbWs6BrdZk7B4dDNpT
Mjkw3bL0YjLOsxygPUWDyExtD1GNV6JAeyTUBlDCKtbrScYxhfjyj1s+B9o+dnifIj94AnpNyaC9
f3QwkNJCTnjOsvRiMi6xrHiaA3ycyYFNbcqBpisl/aoHWaspGdg03uIc43mb/gOilt3CREslQG80
GedmlkC1KyNPBnU9wOPWMp6Aut0S74HfwIQJ7ldTMjBPdBIiGWC0TRkQlseWNmR2tlwC9DmZjEmW
pQ/zOAKqtwdcrnW/DpOBPtp9Ii6F9lhL1yWIo2zUvVhxzYHeLVcG/QfT/iuTA3qwan+zGndVP8p2
k4G8E/wLW4D6PxTlnxgwaDEjaMe6n+USYOvqZKTbUrjQcor3ZSYHRtjULvCrmgwkfY5oRc9B+3Cb
S4FhIhS+gAtZLgH9Y6GWuQU6mwx9IEqYajlA+47CsZ6lGovFBDTNkA9xM4CmpXsAWySDUrPjqZQl
QBsfnSoB41UKAvS9ouJmDfpaDpTQ2WRcXYinCZm+pdyEtDClPgLloP0unABPp3lrpoZ+KkWskSgP
sVZMhlat2t7LQftE2aoCh0sVBOheXclyCYjTp7W19bUsZAQtJuPLTA39gOhg0D7PJtny1xj1tWA+
sUpAG2j7mZaqAh9tzPSVP+XStL+w/qY1XRlfWdOSYXvp7QKnU6Ayqk4jLZcB2zD4gv1iu52qkvG5
NKPsyrCuPs9aDtDeDr4EtS7RRyXNCgfYLPtYfoC33D0Hul6tE6jOfvsMhVqaT8PWG85PXR+WxlOP
pHUIHPNXDsif7NWAT773STdlX6vK4ebi4WRgWybZqFe86tBXUAw4BL+S7UTautTXo9yFcjdKPbsq
PuQTsKdbZ16YLzZrAgdRRvXLCF/Big/R/wXInn5dffdMt8opNs214Bz6cyqNbUDRcZwTIWjDt3m+
XtcBxq3pvL6p6mFftlFUE+i8JPxRCRGoawVbcVepGcF4V4eTGPNPHv+7NjUGAhzmQOl20fyhphlg
T4CxLcQw9WC9Gxb3P4Q37NY4CHJXCuhSW3JnwEXs0qNgSHqVbw210ZP2XwK0A65/6C6NgziaAU5X
wCIUHB4H86227gKH1+JtL3gd1N5sCdACbgZo5rtgnQKx+hLs/ixsdjBXBd2TtyKNhUOp1/dprgMQ
rx9x16fcn1KbttrIyf9OkICWw1KApvY2YyXbpSBobKf7OGXApFtI+5d3Qq1BDoL6V87GcDVc9Ivq
E4D+bjTQbc1i9demreDu8Ch0ffG6hdnmDMrvFbsSsAXczIGk3fwb4VYe+pwBB9Angkd83ADtqgkq
AjetdTTV1icDlfl+Qi3AP4elHEjaDXscHgFjPdNt4ID6S9B9sNLiKoelmuFuJbCpDJi+hvqz2qFw
iIfWc2AQusxPgvq484vH2eUgtpYHH0Hteeqb75ZwMQ+j+cDg9PlwFDwd6o9sr0KtbWI/tSPgp32M
76H+s6mNX3030df5neGq1OtbZDUbOIlFoFaha0L9j0qfCHeAerDqVtODU8+hNThZfR1fHHbpG6kx
9Or1LzUmVVz+HJXDAAAAAElFTkSuQmCC">
<h1 class="title">Intel&reg; Threading Building Blocks.<br>Tachyon sample</h1>
</div>
<p>
Parallel raytracer / renderer that demonstrates the use of parallel_for.
</p>
<p><i>
This example includes software developed by John E. Stone. See
<a href="#copyright">here</a> for copyright information.
</i></p>
<p>
This example is a 2-D raytracer/renderer that visually shows different parallel scheduling
methods and their resulting speedup. The code was parallelized by speculating
that each pixel could be rendered in parallel. The resulting parallel code was
then checked for correctness by using Intel&reg; Thread Checker, which
pointed out where synchronization was needed. Minimal synchronization was then
inserted into the parallel code. The resulting parallel code exhibits good speedup.
</p>
<div class="changes">
<div class="h3-alike">System Requirements</div>
<input type="checkbox">
<div class="show-hide">
<p>
For the most up to date system requirements, see the <a href="http://software.intel.com/en-us/articles/intel-threading-building-blocks-release-notes">release notes.</a>
</p>
</div>
</div>
<div class="changes">
<div class="h3-alike">Versions</div>
<input type="checkbox" checked="checked">
<div class="show-hide">
<dl>
<dt><b>serial</b>
<dd>Original sequential version.
<dt><b>tbb1d</b>
<dd>Parallel version that uses Intel&reg; Threading Building Blocks (Intel&reg; TBB) and blocked_range to parallelize
over tasks that are groups of scan-lines.
<ul>
<li>By default, this version uses one thread per available processor. To change this
default, set the TBB_NUM_THREADS environment variable to the desired number of threads before running.
<li>This version uses the preview feature: auto_range_partitioner. No grain size is provided to blocked_range.
The blocked_range class uses a default grain size of 1 when none is provided. However, the auto_range_partitioner
controls the amount of range splitting dynamically at runtime, resulting in sub-ranges of varying sizes.
</ul>
<dt><b>tbb</b>
<dd>Parallel version that uses Intel TBB and blocked_range2d to parallelize
over tasks that are rectangular sub-areas.
<ul>
<li>By default, this version uses one thread per available processor. To change this
default, set the TBB_NUM_THREADS environment variable to the desired number of threads before running.
<li>This version uses a reasonable task grain size by default. To change this default,
set the TBB_GRAINSIZE environment variable to the desired grain size before running.
The grain size corresponds to the number of pixels (in the X or Y direction, for a
rectangular sub-area) in each parallel task.
</ul>
</dl>
</div>
</div>
<div class="changes">
<div class="h3-alike">Files</div>
<input type="checkbox" checked="checked">
<div class="show-hide">
<dl>
<dt><a href="src/main.cpp">src/main.cpp</a>
<dd>Main program which parses command line options and runs the raytracer.
<dt><a href="src/tachyon_video.cpp">src/tachyon_video.cpp</a>
<dd>Source code for GUI interfaces.
<dt><a href="src/trace.serial.cpp">src/trace.serial.cpp</a>
<dd>Source code for original sequential version of example.
<dt><a href="src/trace.tbb1d.cpp">src/trace.tbb1d.cpp</a>
<dd>Source code for Intel TBB blocked_range (scan-line) version of example.
<dt><a href="src/trace.tbb.cpp">src/trace.tbb.cpp</a>
<dd>Source code for Intel TBB blocked_range2d (rectangular sub-area) version of example.
<dt>(src/*.cpp)
<dd>Remainder of source code for example.
<dt>(src/*.h)
<dd>Remainder of include files for example.
<dt><a href="Makefile">Makefile</a>
<dd>Makefile for building the example.
</dl>
</div>
</div>
<div class="changes">
<div class="h3-alike">Directories</div>
<input type="checkbox" checked="checked">
<div class="show-hide">
<dl>
<dt><a href="src/">src</a>
<dd>Contains source code and include files for the example.
<dt><a href="dat/">dat</a>
<dd>Contains data sets for running the example.
<dt><a href="msvs/">msvs</a>
<dd>Contains Microsoft* Visual Studio* workspace for building and running the example (Windows* systems only).
<dt><a href="xcode/">xcode</a>
<dd>Contains Xcode* IDE workspace for building and running the example (macOS* systems only).
</dl>
<p>For information about the minimum supported version of IDE, see <a href="http://software.intel.com/en-us/articles/intel-threading-building-blocks-release-notes">release notes.</a></p>
</div>
</div>
<div class="changes">
<div class="h3-alike">Build instructions</div>
<input type="checkbox" checked="checked">
<div class="show-hide">
<p>General build directions can be found <a href="../../index.html">here</a>.</p>
<p>
For Windows* systems Microsoft* Visual Studio* projects are provided for each of the above example versions.
</p>
<p>
The Makefile supports the following build targets (in addition to the <a href="../../index.html">general</a> ones).
Here, &lt;<i>version</i>&gt; is one of the above versions of the example, i.e., {serial, tbb1d, tbb}.
</p>
<dl>
<dt><tt>make &lt;<i>version</i>&gt;[_debug]</tt>
<dd>Build and run a single version (release or debug).
Equivalent to 'make build_&lt;<i>version</i>&gt;[_debug] run_&lt;<i>version</i>&gt;'.
<dt><tt>make build_&lt;<i>version</i>&gt;[_debug]</tt>
<dd>Compile and link a single version (release or debug).
The resulting executable is left in the directory for the example.
<dt><tt>make run_&lt;<i>version</i>&gt;</tt>
<dd>Run a single version previously produced by one of the above commands.
<dt><tt>make [(above options or targets)] DATASET={820spheres, balls, balls3, lattice, model2,
teapot, trypsin4pti}</tt>
<dd>Build and run as above, but run with the specified data set.
<dt><tt>make [(above options or targets)] ARGS=-D</tt>
<dd>Build and run as above, but run with disabled run-time display updating for use in making performance measurements
<i>(strongly recommended when measuring performance or scalability; see note below)</i>.
<dt><tt>make [(above options or targets)] UI={con, gdi, d2d, x, mac}</tt>
<dd>Build and run as usual, but build with the specified GUI driver: console, GDI+*, Direct2D*, X11, or OpenGL*
(see the description of the <a href="../../common/index.html">common GUI code</a>
for more information on available graphics support).
For Linux* and macOS* systems, the best available driver is detected automatically by the Makefile.
For Windows* systems, UI=gdi is the default GUI driver; compiling with UI=d2d may offer superior
performance, but can only be used if the Microsoft* DirectX* SDK is installed on your system.
Use UI=con to build without the GUI for use in making performance measurements
<i>(strongly recommended when measuring performance or scalability; see note below)</i>.
<dt><tt>make [(above options or targets)] XARCH=x64</tt>
<dd>Build and run as above, but
also specify XARCH=x64 (or XARCH=AMD64 for older compilers) when building the example on Windows* as a 64-bit binary.
<dt><tt>make [(above options or targets)] DDLIB_DIR=&lt;<i>specify path to Direct Draw* SDK here</i>&gt;</tt>
<dd>If you experience ddraw.lib linking problems, specify the correct library directory via this option.
</dl>
</div>
</div>
<div class="changes">
<div class="h3-alike">Usage</div>
<input type="checkbox" checked="checked">
<div class="show-hide">
<p>
Building via the above make commands, or via Visual Studio projects on Windows* systems, produces executable files
named <tt>tachyon.&lt;<i>version</i>&gt;.exe</tt>. To run these executables directly, use one or more of the following commands.
</p>
<dl>
<dt><tt>tachyon.&lt;<i>version</i>&gt; <i>-h</i></tt>
<dd>Prints the help for command line options
<dt><tt>tachyon.&lt;<i>version</i>&gt; [<i>dataset</i>=value] [<i>boundthresh</i>=value] [<i>no-display-updating</i>] [<i>nobounding</i>] [<i>silent</i>]</tt>
<dt><tt>tachyon.&lt;<i>version</i>&gt; [<i>dataset</i> [<i>boundthresh</i>]] [<i>no-display-updating</i>] [<i>nobounding</i>] [<i>silent</i>]</tt>
<dd><i>dataset</i> is the path/name of one of the *.dat files in the <a href="dat">dat</a> directory for the example.<br>
<i>boundthresh</i> is a bounding threshold value.<br>
<i>no-display-updating</i> - disable run-time display updating.<br>
<i>no-bounding</i> - disable bounding technique.<br>
<i>silent</i> - no output except elapsed time.<br>
<dt><tt>tachyon.&lt;<i>version</i>&gt; [<i>dataset</i>] [<i>no-display-updating</i>]</tt>
<dd>Run this version (release or debug), but run with disabled run-time display updating
for use in making performance measurements
<i>(strongly recommended when measuring performance or scalability; see note below)</i>.
<dt>To run a short version of this example, e.g., for use with Intel&reg; Parallel Inspector:
<dd>Build a <i>debug</i> version of the <tt>tbb</tt> example with the GUI turned off
(e.g., <tt>make UI=con tbb_debug</tt>; see also the build directions above).
<br>Run it with a small dataset, e.g., <tt>tachyon.tbb.exe dat/820spheres.dat no-display-updating</tt>.
</dl>
</div>
</div>
<div class="changes">
<div class="h3-alike">Keys</div>
<input type="checkbox" checked="checked">
<div class="show-hide">
<p>While running with the GUI display turned on the following keyboard keys can be used:</p>
<dl>
<dt><tt>ESC</tt>
<dd>Interrupt the rendering and exit
<dt><tt><i>Any key</i></tt>
<dd>Enable repetition of rendering after the pause. Press ESC to stop the application.
<dt><tt>Space</tt>
<dd>Toggle run-time display updating mode while rendering (see no-display-updating above).
<dt><tt>p</tt>
<dd>Holds the picture after rendering completion. Press 'p' again to continue.
</dl>
</div>
</div>
<div class="changes">
<div class="h3-alike">Notes</div>
<input type="checkbox" checked="checked">
<div class="show-hide">
<ul>
<li>While running with the GUI display turned on should yield reasonable performance in most cases, <i>running with the GUI
display turned off is strongly recommended</i> in order to demonstrate the full performance and scalability of the example.
</ul>
</div>
</div>
<br>
<a href="../index.html">Up to parent directory</a>
<hr>
<a name="copyright"></a>
<div class="changes">
<div class="h3-alike">Legal Information</div>
<input type="checkbox">
<div class="show-hide">
<p>
Intel and the Intel logo are trademarks of Intel Corporation in the U.S. and/or other countries.
<br>* Other names and brands may be claimed as the property of others.
<br>&copy; 2020, Intel Corporation
</p>
<p>
The original source for this example is
Copyright (c) 1994-2008 John E. Stone
All rights reserved.
</p>
<p>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
<ol>
<li>Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
<li>Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
<li>The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
</ol>
</p>
<p>
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
</p>
</div>
</div>
</body>
</html>

View File

@@ -0,0 +1,414 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
The original source for this example is
Copyright (c) 1994-2008 John E. Stone
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/*
* api.cpp - This file contains all of the API calls that are defined for
* external driver code to use.
*/
#include "machine.h"
#include "types.h"
#include "macros.h"
#include "box.h"
#include "cylinder.h"
#include "plane.h"
#include "quadric.h"
#include "ring.h"
#include "sphere.h"
#include "triangle.h"
#include "vol.h"
#include "extvol.h"
#include "texture.h"
#include "light.h"
#include "render.h"
#include "camera.h"
#include "vector.h"
#include "intersect.h"
#include "shade.h"
#include "util.h"
#include "imap.h"
#include "global.h"
#include "tachyon_video.h"
typedef void * SceneHandle;
#include "api.h"
vector rt_vector(apiflt x, apiflt y, apiflt z) {
vector v;
v.x = x;
v.y = y;
v.z = z;
return v;
}
color rt_color(apiflt r, apiflt g, apiflt b) {
color c;
c.r = r;
c.g = g;
c.b = b;
return c;
}
void rt_initialize() {
rpcmsg msg;
reset_object();
reset_lights();
InitTextures();
if (!parinitted) {
parinitted=1;
msg.type=1; /* setup a ping message */
}
}
void rt_renderscene(SceneHandle voidscene) {
scenedef * scene = (scenedef *) voidscene;
renderscene(*scene);
}
void rt_camerasetup(SceneHandle voidscene, apiflt zoom, apiflt aspectratio,
int antialiasing, int raydepth,
vector camcent, vector viewvec, vector upvec) {
scenedef * scene = (scenedef *) voidscene;
vector newupvec;
vector newviewvec;
vector newrightvec;
VCross((vector *) &upvec, &viewvec, &newrightvec);
VNorm(&newrightvec);
VCross((vector *) &viewvec, &newrightvec, &newupvec);
VNorm(&newupvec);
newviewvec=viewvec;
VNorm(&newviewvec);
scene->camzoom=zoom;
scene->aspectratio=aspectratio;
scene->antialiasing=antialiasing;
scene->raydepth=raydepth;
scene->camcent=camcent;
scene->camviewvec=newviewvec;
scene->camrightvec=newrightvec;
scene->camupvec=newupvec;
}
void rt_outputfile(SceneHandle voidscene, const char * outname) {
scenedef * scene = (scenedef *) voidscene;
strcpy((char *) &scene->outfilename, outname);
}
void rt_resolution(SceneHandle voidscene, int hres, int vres) {
scenedef * scene = (scenedef *) voidscene;
scene->hres=hres;
scene->vres=vres;
}
void rt_verbose(SceneHandle voidscene, int v) {
scenedef * scene = (scenedef *) voidscene;
scene->verbosemode = v;
}
void rt_rawimage(SceneHandle voidscene, unsigned char *rawimage) {
scenedef * scene = (scenedef *) voidscene;
scene->rawimage = rawimage;
}
void rt_background(SceneHandle voidscene, color col) {
scenedef * scene = (scenedef *) voidscene;
scene->background.r = col.r;
scene->background.g = col.g;
scene->background.b = col.b;
}
void rt_boundmode(SceneHandle voidscene, int mode) {
scenedef * scene = (scenedef *) voidscene;
scene->boundmode = mode;
}
void rt_boundthresh(SceneHandle voidscene, int threshold) {
scenedef * scene = (scenedef *) voidscene;
if (threshold > 1) {
scene->boundthresh = threshold;
}
else {
rtmesg("Ignoring out-of-range automatic bounding threshold.\n");
rtmesg("Automatic bounding threshold reset to default.\n");
scene->boundthresh = MAXOCTNODES;
}
}
void rt_displaymode(SceneHandle voidscene, int mode) {
scenedef * scene = (scenedef *) voidscene;
scene->displaymode = mode;
}
void rt_scenesetup(SceneHandle voidscene, char * outname, int hres, int vres, int verbose) {
rt_outputfile(voidscene, outname);
rt_resolution(voidscene, hres, vres);
rt_verbose(voidscene, verbose);
}
SceneHandle rt_newscene(void) {
scenedef * scene;
SceneHandle voidscene;
scene = (scenedef *) malloc(sizeof(scenedef));
memset(scene, 0, sizeof(scenedef)); /* clear all valuas to 0 */
voidscene = (SceneHandle) scene;
rt_outputfile(voidscene, "/dev/null"); /* default output file (.tga) */
rt_resolution(voidscene, 512, 512); /* 512x512 resolution */
rt_verbose(voidscene, 0); /* verbose messages off */
rt_rawimage(voidscene, NULL); /* raw image output off */
rt_boundmode(voidscene, RT_BOUNDING_ENABLED); /* spatial subdivision on */
rt_boundthresh(voidscene, MAXOCTNODES); /* default threshold */
rt_displaymode(voidscene, RT_DISPLAY_ENABLED); /* video output on */
rt_camerasetup(voidscene, 1.0, 1.0, 0, 6,
rt_vector(0.0, 0.0, 0.0),
rt_vector(0.0, 0.0, 1.0),
rt_vector(0.0, 1.0, 0.0));
return scene;
}
void rt_deletescene(SceneHandle scene) {
if (scene != NULL)
free(scene);
}
void apitextotex(apitexture * apitex, texture * tex) {
switch(apitex->texturefunc) {
case 0:
tex->texfunc=(color(*)(void *, void *, void *))(standard_texture);
break;
case 1:
tex->texfunc=(color(*)(void *, void *, void *))(checker_texture);
break;
case 2:
tex->texfunc=(color(*)(void *, void *, void *))(grit_texture);
break;
case 3:
tex->texfunc=(color(*)(void *, void *, void *))(marble_texture);
break;
case 4:
tex->texfunc=(color(*)(void *, void *, void *))(wood_texture);
break;
case 5:
tex->texfunc=(color(*)(void *, void *, void *))(gnoise_texture);
break;
case 6:
tex->texfunc=(color(*)(void *, void *, void *))(cyl_checker_texture);
break;
case 7:
tex->texfunc=(color(*)(void *, void *, void *))(image_sphere_texture);
tex->img=AllocateImage((char *)apitex->imap);
break;
case 8:
tex->texfunc=(color(*)(void *, void *, void *))(image_cyl_texture);
tex->img=AllocateImage((char *)apitex->imap);
break;
case 9:
tex->texfunc=(color(*)(void *, void *, void *))(image_plane_texture);
tex->img=AllocateImage((char *)apitex->imap);
break;
default:
tex->texfunc=(color(*)(void *, void *, void *))(standard_texture);
break;
}
tex->ctr = apitex->ctr;
tex->rot = apitex->rot;
tex->scale = apitex->scale;
tex->uaxs = apitex->uaxs;
tex->vaxs = apitex->vaxs;
tex->ambient = apitex->ambient;
tex->diffuse = apitex->diffuse;
tex->specular = apitex->specular;
tex->opacity = apitex->opacity;
tex->col = apitex->col;
tex->islight = 0;
tex->shadowcast = 1;
tex->phong = 0.0;
tex->phongexp = 0.0;
tex->phongtype = 0;
}
void * rt_texture(apitexture * apitex) {
texture * tex;
tex=(texture *)rt_getmem(sizeof(texture));
apitextotex(apitex, tex);
return(tex);
}
void rt_tex_color(void * voidtex, color col) {
texture * tex = (texture *) voidtex;
tex->col = col;
}
void rt_tex_phong(void * voidtex, apiflt phong, apiflt phongexp, int type) {
texture * tex = (texture *) voidtex;
tex->phong = phong;
tex->phongexp = phongexp;
tex->phongtype = type;
}
void rt_light(void * tex, vector ctr, apiflt rad) {
point_light * li;
li=newlight(tex, (vector) ctr, rad);
li->tex->islight=1;
li->tex->shadowcast=1;
li->tex->diffuse=0.0;
li->tex->specular=0.0;
li->tex->opacity=1.0;
add_light(li);
add_object((object *)li);
}
void rt_scalarvol(void * tex, vector min, vector max,
int xs, int ys, int zs, char * fname, void * invol) {
add_object((object *) newscalarvol(tex, (vector)min, (vector)max, xs, ys, zs, fname, (scalarvol *) invol));
}
void rt_extvol(void * tex, vector min, vector max, int samples, flt (* evaluator)(flt, flt, flt)) {
add_object((object *) newextvol(tex, (vector)min, (vector)max, samples, evaluator));
}
void rt_box(void * tex, vector min, vector max) {
add_object((object *) newbox(tex, (vector)min, (vector)max));
}
void rt_cylinder(void * tex, vector ctr, vector axis, apiflt rad) {
add_object(newcylinder(tex, (vector)ctr, (vector)axis, rad));
}
void rt_fcylinder(void * tex, vector ctr, vector axis, apiflt rad) {
add_object(newfcylinder(tex, (vector)ctr, (vector)axis, rad));
}
void rt_plane(void * tex, vector ctr, vector norm) {
add_object(newplane(tex, (vector)ctr, (vector)norm));
}
void rt_ring(void * tex, vector ctr, vector norm, apiflt a, apiflt b) {
add_object(newring(tex, (vector)ctr, (vector)norm, a, b));
}
void rt_sphere(void * tex, vector ctr, apiflt rad) {
add_object(newsphere(tex, (vector)ctr, rad));
}
void rt_tri(void * tex, vector v0, vector v1, vector v2) {
object * trn;
trn = newtri(tex, (vector)v0, (vector)v1, (vector)v2);
if (trn != NULL) {
add_object(trn);
}
}
void rt_stri(void * tex, vector v0, vector v1, vector v2,
vector n0, vector n1, vector n2) {
object * trn;
trn = newstri(tex, (vector)v0, (vector)v1, (vector)v2, (vector)n0, (vector)n1, (vector)n2);
if (trn != NULL) {
add_object(trn);
}
}
void rt_quadsphere(void * tex, vector ctr, apiflt rad) {
quadric * q;
flt factor;
q=(quadric *) newquadric();
factor= 1.0 / (rad*rad);
q->tex=(texture *)tex;
q->ctr=ctr;
q->mat.a=factor;
q->mat.b=0.0;
q->mat.c=0.0;
q->mat.d=0.0;
q->mat.e=factor;
q->mat.f=0.0;
q->mat.g=0.0;
q->mat.h=factor;
q->mat.i=0.0;
q->mat.j=-1.0;
add_object((object *)q);
}

View File

@@ -0,0 +1,204 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
The original source for this example is
Copyright (c) 1994-2008 John E. Stone
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/*****************************************************************************
* api.h - The declarations and prototypes needed so that 3rd party driver *
* code can run the raytracer. Third party driver code should *
* only use the functions in this header file to interface with *
* the rendering engine. *
*************************************************************************** */
/*
* $Id: api.h,v 1.2 2007-02-22 17:54:15 Exp $
*/
/********************************************/
/* Types defined for use with the API calls */
/********************************************/
#ifdef USESINGLEFLT
typedef float apiflt; /* generic floating point number */
#else
typedef double apiflt; /* generic floating point number */
#endif
typedef void * SceneHandle;
typedef struct {
int texturefunc; /* which texture function to use */
color col; /* base object color */
int shadowcast; /* does the object cast a shadow */
apiflt ambient; /* ambient lighting */
apiflt diffuse; /* diffuse reflection */
apiflt specular; /* specular reflection */
apiflt opacity; /* how opaque the object is */
vector ctr; /* origin of texture */
vector rot; /* rotation of texture around origin */
vector scale; /* scale of texture in x,y,z */
vector uaxs; /* planar map u axis */
vector vaxs; /* planar map v axis */
char imap[96]; /* name of image map */
} apitexture;
/*******************************************************************
* NOTE: The value passed in apitexture.texturefunc corresponds to
* the meanings given in this table:
*
* 0 - No texture function is applied other than standard lighting.
* 1 - 3D checkerboard texture. Red & Blue checkers through 3d space.
* 2 - Grit texture, roughens up the surface of the object a bit.
* 3 - 3D marble texture. Makes a 3D swirl pattern through the object.
* 4 - 3D wood texture. Makes a 3D wood pattern through the object.
* 5 - 3D gradient noise function.
* 6 - I've forgotten :-)
* 7 - Cylindrical Image Map **** IMAGE MAPS REQUIRE the filename
* 8 - Spherical Image Map of the image be put in imap[]
* 9 - Planar Image Map part of the texture...
* planar requires uaxs, and vaxs..
*
*******************************************************************/
/********************************************/
/* Functions implemented to provide the API */
/********************************************/
vector rt_vector(apiflt x, apiflt y, apiflt z); /* helper to make vectors */
color rt_color(apiflt r, apiflt g, apiflt b); /* helper to make colors */
void rt_initialize();/* reset raytracer, memory deallocation */
void rt_finalize(void); /* close down for good.. */
SceneHandle rt_newscene(void); /* allocate new scene */
void rt_deletescene(SceneHandle); /* delete a scene */
void rt_renderscene(SceneHandle); /* raytrace the current scene */
void rt_outputfile(SceneHandle, const char * outname);
void rt_resolution(SceneHandle, int hres, int vres);
void rt_verbose(SceneHandle, int v);
void rt_rawimage(SceneHandle, unsigned char *rawimage);
void rt_background(SceneHandle, color);
/* Parameter values for rt_boundmode() */
#define RT_BOUNDING_DISABLED 0
#define RT_BOUNDING_ENABLED 1
void rt_boundmode(SceneHandle, int);
void rt_boundthresh(SceneHandle, int);
/* Parameter values for rt_displaymode() */
#define RT_DISPLAY_DISABLED 0
#define RT_DISPLAY_ENABLED 1
void rt_displaymode(SceneHandle, int);
void rt_scenesetup(SceneHandle, char *, int, int, int);
/* scene, output filename, horizontal resolution, vertical resolution,
verbose mode */
void rt_camerasetup(SceneHandle, apiflt, apiflt, int, int,
vector, vector, vector);
/* camera parms: scene, zoom, aspectratio, antialiasing, raydepth,
camera center, view direction, up direction */
void * rt_texture(apitexture *);
/* pointer to the texture struct that would have been passed to each
object() call in older revisions.. */
void rt_light(void * , vector, apiflt); /* add a light */
/* light parms: texture, center, radius */
void rt_sphere(void *, vector, apiflt); /* add a sphere */
/* sphere parms: texture, center, radius */
void rt_scalarvol(void *, vector, vector,
int, int, int, char *, void *);
void rt_extvol(void *, vector, vector, int, apiflt (* evaluator)(apiflt, apiflt, apiflt));
void rt_box(void *, vector, vector);
/* box parms: texture, min, max */
void rt_plane(void *, vector, vector);
/* plane parms: texture, center, normal */
void rt_ring(void *, vector, vector, apiflt, apiflt);
/* ring parms: texture, center, normal, inner, outer */
void rt_tri(void *, vector, vector, vector);
/* tri parms: texture, vertex 0, vertex 1, vertex 2 */
void rt_stri(void *, vector, vector, vector,
vector, vector, vector);
/* stri parms: texture, vertex 0, vertex 1, vertex 2, norm 0, norm 1, norm 2 */
void rt_heightfield(void *, vector, int, int, apiflt *, apiflt, apiflt);
/* field parms: texture, center, m, n, field, wx, wy */
void rt_landscape(void *, int, int, vector, apiflt, apiflt);
void rt_quadsphere(void *, vector, apiflt); /* add quadric sphere */
/* sphere parms: texture, center, radius */
void rt_cylinder(void *, vector, vector, apiflt);
void rt_fcylinder(void *, vector, vector, apiflt);
void rt_polycylinder(void *, vector *, int, apiflt);
/* new texture handling routines */
void rt_tex_color(void * voidtex, color col);
#define RT_PHONG_PLASTIC 0
#define RT_PHONG_METAL 1
void rt_tex_phong(void * voidtex, apiflt phong, apiflt phongexp, int type);

View File

@@ -0,0 +1,264 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
The original source for this example is
Copyright (c) 1994-2008 John E. Stone
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/*
* api.cpp - This file contains all of the API calls that are defined for
* external driver code to use.
*/
#include "machine.h"
#include "types.h"
#include "api.h"
#include "macros.h"
#include "vector.h"
#define MyVNorm(a) VNorm ((vector *) a)
void rt_polycylinder(void * tex, vector * points, int numpts, apiflt rad) {
vector a;
int i;
if ((points == NULL) || (numpts == 0)) {
return;
}
if (numpts > 0) {
rt_sphere(tex, points[0], rad);
if (numpts > 1) {
for (i=1; i<numpts; i++) {
a.x = points[i].x - points[i-1].x;
a.y = points[i].y - points[i-1].y;
a.z = points[i].z - points[i-1].z;
rt_fcylinder(tex, points[i-1], a, rad);
rt_sphere(tex, points[i], rad);
}
}
}
}
void rt_heightfield(void * tex, vector ctr, int m, int n,
apiflt * field, apiflt wx, apiflt wy) {
int xx,yy;
vector v0, v1, v2;
apiflt xoff, yoff, zoff;
xoff=ctr.x - (wx / 2.0);
yoff=ctr.z - (wy / 2.0);
zoff=ctr.y;
for (yy=0; yy<(n-1); yy++) {
for (xx=0; xx<(m-1); xx++) {
v0.x=wx*(xx )/(m*1.0) + xoff;
v0.y=field[(yy )*m + (xx )] + zoff;
v0.z=wy*(yy )/(n*1.0) + yoff;
v1.x=wx*(xx + 1)/(m*1.0) + xoff;
v1.y=field[(yy )*m + (xx + 1)] + zoff;
v1.z=wy*(yy )/(n*1.0) + yoff;
v2.x=wx*(xx + 1)/(m*1.0) + xoff;
v2.y=field[(yy + 1)*m + (xx + 1)] + zoff;
v2.z=wy*(yy + 1)/(n*1.0) + yoff;
rt_tri(tex, v1, v0, v2);
v0.x=wx*(xx )/(m*1.0) + xoff;
v0.y=field[(yy )*m + (xx )] + zoff;
v0.z=wy*(yy )/(n*1.0) + yoff;
v1.x=wx*(xx )/(m*1.0) + xoff;
v1.y=field[(yy + 1)*m + (xx )] + zoff;
v1.z=wy*(yy + 1)/(n*1.0) + yoff;
v2.x=wx*(xx + 1)/(m*1.0) + xoff;
v2.y=field[(yy + 1)*m + (xx + 1)] + zoff;
v2.z=wy*(yy + 1)/(n*1.0) + yoff;
rt_tri(tex, v0, v1, v2);
}
}
} /* end of heightfield */
static void rt_sheightfield(void * tex, vector ctr, int m, int n,
apiflt * field, apiflt wx, apiflt wy) {
vector * vertices;
vector * normals;
vector offset;
apiflt xinc, yinc;
int x, y, addr;
vertices = (vector *) malloc(m*n*sizeof(vector));
normals = (vector *) malloc(m*n*sizeof(vector));
offset.x = ctr.x - (wx / 2.0);
offset.y = ctr.z - (wy / 2.0);
offset.z = ctr.y;
xinc = wx / ((apiflt) m);
yinc = wy / ((apiflt) n);
/* build vertex list */
for (y=0; y<n; y++) {
for (x=0; x<m; x++) {
addr = y*m + x;
vertices[addr] = rt_vector(
x * xinc + offset.x,
field[addr] + offset.z,
y * yinc + offset.y);
}
}
/* build normals from vertex list */
for (x=1; x<m; x++) {
normals[x] = normals[(n - 1)*m + x] = rt_vector(0.0, 1.0, 0.0);
}
for (y=1; y<n; y++) {
normals[y*m] = normals[y*m + (m-1)] = rt_vector(0.0, 1.0, 0.0);
}
for (y=1; y<(n-1); y++) {
for (x=1; x<(m-1); x++) {
addr = y*m + x;
normals[addr] = rt_vector(
-(field[addr + 1] - field[addr - 1]) / (2.0 * xinc),
1.0,
-(field[addr + m] - field[addr - m]) / (2.0 * yinc));
MyVNorm(&normals[addr]);
}
}
/* generate actual triangles */
for (y=0; y<(n-1); y++) {
for (x=0; x<(m-1); x++) {
addr = y*m + x;
rt_stri(tex, vertices[addr], vertices[addr + 1 + m], vertices[addr + 1],
normals[addr], normals[addr + 1 + m], normals[addr + 1]);
rt_stri(tex, vertices[addr], vertices[addr + m], vertices[addr + 1 + m],
normals[addr], normals[addr + m], normals[addr + 1 + m]);
}
}
free(normals);
free(vertices);
} /* end of smoothed heightfield */
static void adjust(apiflt *base, int xres, int yres, apiflt wx, apiflt wy,
int xa, int ya, int x, int y, int xb, int yb) {
apiflt d, v;
if (base[x + (xres*y)]==0.0) {
d=(abs(xa - xb) / (xres * 1.0))*wx + (abs(ya - yb) / (yres * 1.0))*wy;
v=(base[xa + (xres*ya)] + base[xb + (xres*yb)]) / 2.0 +
(((((rand() % 1000) - 500.0)/500.0)*d) / 8.0);
if (v < 0.0) v=0.0;
if (v > (xres + yres)) v=(xres + yres);
base[x + (xres * y)]=v;
}
}
static void subdivide(apiflt *base, int xres, int yres, apiflt wx, apiflt wy,
int x1, int y1, int x2, int y2) {
long x,y;
if (((x2 - x1) < 2) && ((y2 - y1) < 2)) { return; }
x=(x1 + x2) / 2;
y=(y1 + y2) / 2;
adjust(base, xres, yres, wx, wy, x1, y1, x, y1, x2, y1);
adjust(base, xres, yres, wx, wy, x2, y1, x2, y, x2, y2);
adjust(base, xres, yres, wx, wy, x1, y2, x, y2, x2, y2);
adjust(base, xres, yres, wx, wy, x1, y1, x1, y, x1, y2);
if (base[x + xres*y]==0.0) {
base[x + (xres * y)]=(base[x1 + xres*y1] + base[x2 + xres*y1] +
base[x2 + xres*y2] + base[x1 + xres*y2] )/4.0;
}
subdivide(base, xres, yres, wx, wy, x1, y1 ,x ,y);
subdivide(base, xres, yres, wx, wy, x, y1, x2, y);
subdivide(base, xres, yres, wx, wy, x, y, x2, y2);
subdivide(base, xres, yres, wx, wy, x1, y, x, y2);
}
void rt_landscape(void * tex, int m, int n,
vector ctr, apiflt wx, apiflt wy) {
int totalsize, x, y;
apiflt * field;
totalsize=m*n;
srand(totalsize);
field=(apiflt *) malloc(totalsize*sizeof(apiflt));
for (y=0; y<n; y++) {
for (x=0; x<m; x++) {
field[x + y*m]=0.0;
}
}
field[0 + 0]=1.0 + (rand() % 100)/100.0;
field[m - 1]=1.0 + (rand() % 100)/100.0;
field[0 + m*(n - 1)]=1.0 + (rand() % 100)/100.0;
field[m - 1 + m*(n - 1)]=1.0 + (rand() % 100)/100.0;
subdivide(field, m, n, wx, wy, 0, 0, m-1, n-1);
rt_sheightfield(tex, ctr, m, n, field, wx, wy);
free(field);
}

View File

@@ -0,0 +1,222 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
The original source for this example is
Copyright (c) 1994-2008 John E. Stone
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/*
* apitrigeom.cpp - This file contains code for generating triangle tessellated
* geometry, for use with OpenGL, XGL, etc.
*/
#include "machine.h"
#include "types.h"
#include "api.h"
#include "macros.h"
#include "vector.h"
#define MyVNorm(a) VNorm ((vector *) a)
#define MyVCross(a,b,c) VCross ((vector *) a, (vector *) b, (vector *) c)
#define MyVAddS(x,a,b,c) VAddS ((flt) x, (vector *) a, (vector *) b, (vector *) c)
#define CYLFACETS 36
#define RINGFACETS 36
#define SPHEREFACETS 25
void rt_tri_fcylinder(void * tex, vector ctr, vector axis, apiflt rad) {
vector x, y, z, tmp;
double u, v, u2, v2;
int j;
vector p1, p2, p3, p4;
vector n1, n2;
z = axis;
MyVNorm(&z);
tmp.x = z.y - 2.1111111;
tmp.y = -z.z + 3.14159267;
tmp.z = z.x - 3.915292342341;
MyVNorm(&z);
MyVNorm(&tmp);
MyVCross(&z, &tmp, &x);
MyVNorm(&x);
MyVCross(&x, &z, &y);
MyVNorm(&y);
for (j=0; j<CYLFACETS; j++) {
u = rad * sin((6.28 * j) / (CYLFACETS - 1.0));
v = rad * cos((6.28 * j) / (CYLFACETS - 1.0));
u2 = rad * sin((6.28 * (j + 1.0)) / (CYLFACETS - 1.0));
v2 = rad * cos((6.28 * (j + 1.0)) / (CYLFACETS - 1.0));
p1.x = p1.y = p1.z = 0.0;
p4 = p3 = p2 = p1;
MyVAddS(u, &x, &p1, &p1);
MyVAddS(v, &y, &p1, &p1);
n1 = p1;
MyVNorm(&n1);
MyVAddS(1.0, &ctr, &p1, &p1);
MyVAddS(u2, &x, &p2, &p2);
MyVAddS(v2, &y, &p2, &p2);
n2 = p2;
MyVNorm(&n2);
MyVAddS(1.0, &ctr, &p2, &p2);
MyVAddS(1.0, &axis, &p1, &p3);
MyVAddS(1.0, &axis, &p2, &p4);
rt_stri(tex, p1, p2, p3, n1, n2, n1);
rt_stri(tex, p3, p2, p4, n1, n2, n2);
}
}
void rt_tri_cylinder(void * tex, vector ctr, vector axis, apiflt rad) {
rt_fcylinder(tex, ctr, axis, rad);
}
void rt_tri_ring(void * tex, vector ctr, vector norm, apiflt a, apiflt b) {
vector x, y, z, tmp;
double u, v, u2, v2;
int j;
vector p1, p2, p3, p4;
vector n1, n2;
z = norm;
MyVNorm(&z);
tmp.x = z.y - 2.1111111;
tmp.y = -z.z + 3.14159267;
tmp.z = z.x - 3.915292342341;
MyVNorm(&z);
MyVNorm(&tmp);
MyVCross(&z, &tmp, &x);
MyVNorm(&x);
MyVCross(&x, &z, &y);
MyVNorm(&y);
for (j=0; j<RINGFACETS; j++) {
u = sin((6.28 * j) / (RINGFACETS - 1.0));
v = cos((6.28 * j) / (RINGFACETS - 1.0));
u2 = sin((6.28 * (j + 1.0)) / (RINGFACETS - 1.0));
v2 = cos((6.28 * (j + 1.0)) / (RINGFACETS - 1.0));
p1.x = p1.y = p1.z = 0.0;
p4 = p3 = p2 = p1;
MyVAddS(u, &x, &p1, &p1);
MyVAddS(v, &y, &p1, &p1);
n1 = p1;
MyVNorm(&n1);
MyVAddS(a, &n1, &ctr, &p1);
MyVAddS(b, &n1, &ctr, &p3);
MyVAddS(u2, &x, &p2, &p2);
MyVAddS(v2, &y, &p2, &p2);
n2 = p2;
MyVNorm(&n2);
MyVAddS(a, &n2, &ctr, &p2);
MyVAddS(b, &n2, &ctr, &p4);
rt_stri(tex, p1, p2, p3, norm, norm, norm);
rt_stri(tex, p3, p2, p4, norm, norm, norm);
}
}
void rt_tri_box(void * tex, vector min, vector max) {
/* -XY face */
rt_tri(tex, rt_vector(min.x, min.y, min.z),
rt_vector(min.x, max.y, min.z),
rt_vector(max.x, max.y, min.z));
rt_tri(tex, rt_vector(min.x, min.y, min.z),
rt_vector(max.x, max.y, min.z),
rt_vector(max.x, min.y, min.z));
/* +XY face */
rt_tri(tex, rt_vector(min.x, min.y, max.z),
rt_vector(max.x, max.y, max.z),
rt_vector(min.x, max.y, max.z));
rt_tri(tex, rt_vector(min.x, min.y, max.z),
rt_vector(max.x, min.y, max.z),
rt_vector(max.x, max.y, max.z));
/* -YZ face */
rt_tri(tex, rt_vector(min.x, min.y, min.z),
rt_vector(min.x, max.y, max.z),
rt_vector(min.x, min.y, max.z));
rt_tri(tex, rt_vector(min.x, min.y, min.z),
rt_vector(min.x, max.y, min.z),
rt_vector(min.x, max.y, max.z));
/* +YZ face */
rt_tri(tex, rt_vector(max.x, min.y, min.z),
rt_vector(max.x, min.y, max.z),
rt_vector(max.x, max.y, max.z));
rt_tri(tex, rt_vector(max.x, min.y, min.z),
rt_vector(max.x, max.y, max.z),
rt_vector(max.x, max.y, min.z));
/* -XZ face */
rt_tri(tex, rt_vector(min.x, min.y, min.z),
rt_vector(min.x, min.y, max.z),
rt_vector(max.x, min.y, max.z));
rt_tri(tex, rt_vector(min.x, min.y, min.z),
rt_vector(max.x, min.y, max.z),
rt_vector(max.x, min.y, min.z));
/* +XZ face */
rt_tri(tex, rt_vector(min.x, max.y, min.z),
rt_vector(max.x, max.y, max.z),
rt_vector(min.x, max.y, max.z));
rt_tri(tex, rt_vector(min.x, max.y, min.z),
rt_vector(max.x, max.y, min.z),
rt_vector(max.x, max.y, max.z));
}
void rt_tri_sphere(void * tex, vector ctr, apiflt rad) {
}
void rt_tri_plane(void * tex, vector ctr, vector norm) {
rt_tri_ring(tex, ctr, norm, 0.0, 10000.0);
}

View File

@@ -0,0 +1,56 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
The original source for this example is
Copyright (c) 1994-2008 John E. Stone
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/*
* apitrigeom.h - header for functions to generate triangle tessellated
* geometry for use with OpenGL, XGL, etc.
*
*/
void rt_tri_fcylinder(void * tex, vector ctr, vector axis, apiflt rad);
void rt_tri_cylinder(void * tex, vector ctr, vector axis, apiflt rad);
void rt_tri_ring(void * tex, vector ctr, vector norm, apiflt a, apiflt b);
void rt_tri_plane(void * tex, vector ctr, vector norm);
void rt_tri_box(void * tex, vector min, vector max);

View File

@@ -0,0 +1,178 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
The original source for this example is
Copyright (c) 1994-2008 John E. Stone
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/*
* bndbox.cpp - This file contains the functions for dealing with bounding boxes.
*/
#include "machine.h"
#include "types.h"
#include "macros.h"
#include "vector.h"
#include "intersect.h"
#include "util.h"
#define BNDBOX_PRIVATE
#include "bndbox.h"
static object_methods bndbox_methods = {
(void (*)(void *, void *))(bndbox_intersect),
(void (*)(void *, void *, void *, void *))(NULL),
bndbox_bbox,
free_bndbox
};
bndbox * newbndbox(vector min, vector max) {
bndbox * b;
b=(bndbox *) rt_getmem(sizeof(bndbox));
memset(b, 0, sizeof(bndbox));
b->min=min;
b->max=max;
b->methods = &bndbox_methods;
b->objlist=NULL;
b->tex=NULL;
b->nextobj=NULL;
return b;
}
static int bndbox_bbox(void * obj, vector * min, vector * max) {
bndbox * b = (bndbox *) obj;
*min = b->min;
*max = b->max;
return 1;
}
static void free_bndbox(void * v) {
bndbox * b = (bndbox *) v;
free_objects(b->objlist);
free(b);
}
static void bndbox_intersect(bndbox * bx, ray * ry) {
flt a, tx1, tx2, ty1, ty2, tz1, tz2;
flt tnear, tfar;
object * obj;
ray newray;
/* eliminate bounded rays whose bounds do not intersect */
/* the bounds of the box.. */
if (ry->flags & RT_RAY_BOUNDED) {
if ((ry->s.x > bx->max.x) && (ry->e.x > bx->max.x)) return;
if ((ry->s.x < bx->min.x) && (ry->e.x < bx->min.x)) return;
if ((ry->s.y > bx->max.y) && (ry->e.y > bx->max.y)) return;
if ((ry->s.y < bx->min.y) && (ry->e.y < bx->min.y)) return;
if ((ry->s.z > bx->max.z) && (ry->e.z > bx->max.z)) return;
if ((ry->s.z < bx->min.z) && (ry->e.z < bx->min.z)) return;
}
tnear= -FHUGE;
tfar= FHUGE;
if (ry->d.x == 0.0) {
if ((ry->o.x < bx->min.x) || (ry->o.x > bx->max.x)) return;
}
else {
tx1 = (bx->min.x - ry->o.x) / ry->d.x;
tx2 = (bx->max.x - ry->o.x) / ry->d.x;
if (tx1 > tx2) { a=tx1; tx1=tx2; tx2=a; }
if (tx1 > tnear) tnear=tx1;
if (tx2 < tfar) tfar=tx2;
}
if (tnear > tfar) return;
if (tfar < 0.0) return;
if (ry->d.y == 0.0) {
if ((ry->o.y < bx->min.y) || (ry->o.y > bx->max.y)) return;
}
else {
ty1 = (bx->min.y - ry->o.y) / ry->d.y;
ty2 = (bx->max.y - ry->o.y) / ry->d.y;
if (ty1 > ty2) { a=ty1; ty1=ty2; ty2=a; }
if (ty1 > tnear) tnear=ty1;
if (ty2 < tfar) tfar=ty2;
}
if (tnear > tfar) return;
if (tfar < 0.0) return;
if (ry->d.z == 0.0) {
if ((ry->o.z < bx->min.z) || (ry->o.z > bx->max.z)) return;
}
else {
tz1 = (bx->min.z - ry->o.z) / ry->d.z;
tz2 = (bx->max.z - ry->o.z) / ry->d.z;
if (tz1 > tz2) { a=tz1; tz1=tz2; tz2=a; }
if (tz1 > tnear) tnear=tz1;
if (tz2 < tfar) tfar=tz2;
}
if (tnear > tfar) return;
if (tfar < 0.0) return;
/* intersect all of the enclosed objects */
newray=*ry;
newray.flags |= RT_RAY_BOUNDED;
RAYPNT(newray.s , (*ry) , tnear);
RAYPNT(newray.e , (*ry) , (tfar + EPSILON));
obj = bx->objlist;
while (obj != NULL) {
obj->methods->intersect(obj, &newray);
obj = (object *)obj->nextobj;
}
}

View File

@@ -0,0 +1,70 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
The original source for this example is
Copyright (c) 1994-2008 John E. Stone
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/*
* bndbox.h - This file contains the defines for bounding boxes etc.
*
* $Id: bndbox.h,v 1.2 2007-02-22 17:54:15 Exp $
*/
typedef struct {
unsigned int id; /* Unique Object serial number */
void * nextobj; /* pointer to next object in list */
object_methods * methods; /* this object's methods */
texture * tex; /* object texture */
vector min;
vector max;
object * objlist;
} bndbox;
bndbox * newbndbox(vector min, vector max);
#ifdef BNDBOX_PRIVATE
static int bndbox_bbox(void * obj, vector * min, vector * max);
static void free_bndbox(void * v);
static void bndbox_intersect(bndbox *, ray *);
#endif

View File

@@ -0,0 +1,164 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
The original source for this example is
Copyright (c) 1994-2008 John E. Stone
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/*
* box.cpp - This file contains the functions for dealing with boxes.
*/
#include "machine.h"
#include "types.h"
#include "macros.h"
#include "box.h"
#include "vector.h"
#include "intersect.h"
#include "util.h"
int box_bbox(void * obj, vector * min, vector * max) {
box * b = (box *) obj;
*min = b->min;
*max = b->max;
return 1;
}
static object_methods box_methods = {
(void (*)(void *, void *))(box_intersect),
(void (*)(void *, void *, void *, void *))(box_normal),
box_bbox,
free
};
box * newbox(void * tex, vector min, vector max) {
box * b;
b=(box *) rt_getmem(sizeof(box));
memset(b, 0, sizeof(box));
b->methods = &box_methods;
b->tex = (texture *)tex;
b->min = min;
b->max = max;
return b;
}
void box_intersect(box * bx, ray * ry) {
flt a, tx1, tx2, ty1, ty2, tz1, tz2;
flt tnear, tfar;
tnear= -FHUGE;
tfar= FHUGE;
if (ry->d.x == 0.0) {
if ((ry->o.x < bx->min.x) || (ry->o.x > bx->max.x)) return;
}
else {
tx1 = (bx->min.x - ry->o.x) / ry->d.x;
tx2 = (bx->max.x - ry->o.x) / ry->d.x;
if (tx1 > tx2) { a=tx1; tx1=tx2; tx2=a; }
if (tx1 > tnear) tnear=tx1;
if (tx2 < tfar) tfar=tx2;
}
if (tnear > tfar) return;
if (tfar < 0.0) return;
if (ry->d.y == 0.0) {
if ((ry->o.y < bx->min.y) || (ry->o.y > bx->max.y)) return;
}
else {
ty1 = (bx->min.y - ry->o.y) / ry->d.y;
ty2 = (bx->max.y - ry->o.y) / ry->d.y;
if (ty1 > ty2) { a=ty1; ty1=ty2; ty2=a; }
if (ty1 > tnear) tnear=ty1;
if (ty2 < tfar) tfar=ty2;
}
if (tnear > tfar) return;
if (tfar < 0.0) return;
if (ry->d.z == 0.0) {
if ((ry->o.z < bx->min.z) || (ry->o.z > bx->max.z)) return;
}
else {
tz1 = (bx->min.z - ry->o.z) / ry->d.z;
tz2 = (bx->max.z - ry->o.z) / ry->d.z;
if (tz1 > tz2) { a=tz1; tz1=tz2; tz2=a; }
if (tz1 > tnear) tnear=tz1;
if (tz2 < tfar) tfar=tz2;
}
if (tnear > tfar) return;
if (tfar < 0.0) return;
add_intersection(tnear, (object *) bx, ry);
add_intersection(tfar, (object *) bx, ry);
}
void box_normal(box * bx, vector * pnt, ray * incident, vector * N) {
vector a, b, c;
flt t;
c.x=(bx->max.x + bx->min.x) / 2.0;
c.y=(bx->max.y + bx->min.y) / 2.0;
c.z=(bx->max.z + bx->min.z) / 2.0;
VSub((vector *) pnt, &c, N);
b=(*N);
a.x=fabs(N->x);
a.y=fabs(N->y);
a.z=fabs(N->z);
N->x=0.0; N->y=0.0; N->z=0.0;
t=MYMAX(a.x, MYMAX(a.y, a.z));
if (t==a.x) N->x=b.x;
if (t==a.y) N->y=b.y;
if (t==a.z) N->z=b.z;
VNorm(N);
}

View File

@@ -0,0 +1,65 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
The original source for this example is
Copyright (c) 1994-2008 John E. Stone
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/*
* box.h - This file contains the defines for boxes etc.
*
* $Id: box.h,v 1.2 2007-02-22 17:54:15 Exp $
*/
typedef struct {
unsigned int id; /* Unique Object serial number */
void * nextobj; /* pointer to next object in list */
object_methods * methods; /* this object's methods */
texture * tex; /* object texture */
vector min;
vector max;
} box;
box * newbox(void * tex, vector min, vector max);
void box_intersect(box *, ray *);
void box_normal(box *, vector *, ray * incident, vector *);

View File

@@ -0,0 +1,105 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
The original source for this example is
Copyright (c) 1994-2008 John E. Stone
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/*
* camera.cpp - This file contains all of the functions for doing camera work.
*/
#include "machine.h"
#include "types.h"
#include "macros.h"
#include "vector.h"
#include "camera.h"
#include "util.h"
ray camray(scenedef *scene, int x, int y) {
ray ray1, newray;
vector projcent;
vector projpixel;
flt px, py, sx, sy;
sx = (flt) scene->hres;
sy = (flt) scene->vres;
/* calculate the width and height of the image plane given the */
/* aspect ratio, image resolution, and zoom factor */
px=((sx / sy) / scene->aspectratio) / scene->camzoom;
py=1.0 / scene->camzoom;
/* assuming viewvec is a unit vector, then the center of the */
/* image plane is the camera center + vievec */
projcent.x = scene->camcent.x + scene->camviewvec.x;
projcent.y = scene->camcent.y + scene->camviewvec.y;
projcent.z = scene->camcent.z + scene->camviewvec.z;
/* starting from the center of the image plane, we move the */
/* center of the pel we're calculating, to */
/* projcent + (rightvec * x distance) */
ray1.o=projcent;
ray1.d=scene->camrightvec;
projpixel=Raypnt(&ray1, ((x*px/sx) - (px / 2.0)));
/* starting from the horizontally translated pel, we move the */
/* center of the pel we're calculating, to */
/* projcent + (upvec * y distance) */
ray1.o=projpixel;
ray1.d=scene->camupvec;
projpixel=Raypnt(&ray1, ((y*py/sy) - (py / 2.0)));
/* now that we have the exact pel center in the image plane */
/* we create the real primary ray that will be used by the */
/* rest of the system. */
/* The ray is expected to be re-normalized elsewhere, we're */
/* only really concerned about getting its direction right. */
newray.o=scene->camcent;
VSub(&projpixel, &scene->camcent, &newray.d);
newray.depth = scene->raydepth;
newray.flags = RT_RAY_REGULAR; /* camera only generates primary rays */
return newray;
}

View File

@@ -0,0 +1,52 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
The original source for this example is
Copyright (c) 1994-2008 John E. Stone
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/*
* camera.h - This file contains the defines for camera routines etc.
*
* $Id: camera.h,v 1.2 2007-02-22 17:54:15 Exp $
*/
ray camray(scenedef *, int, int);

View File

@@ -0,0 +1,92 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
The original source for this example is
Copyright (c) 1994-2008 John E. Stone
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/*
* coordsys.cpp - Routines to translate from one coordinate system to another.
*/
#include "machine.h"
#include "types.h"
#include "coordsys.h"
void xytopolar(flt x, flt y, flt rad, flt * u, flt * v) {
flt r1;
r1=x*x + y*y;
*v=sqrt(r1 / (rad*rad));
if (y<0.0)
*u=1.0 - acos(x/sqrt(r1))/TWOPI;
else
*u= acos(x/sqrt(r1))/TWOPI;
}
void xyztocyl(vector pnt, flt height, flt * u, flt * v) {
flt r1;
r1=pnt.x*pnt.x + pnt.y*pnt.y;
*v=pnt.z / height;
if (pnt.y<0.0)
*u=1.0 - acos(pnt.x/sqrt(r1))/TWOPI;
else
*u=acos(pnt.x/sqrt(r1))/TWOPI;
}
void xyztospr(vector pnt, flt * u, flt * v) {
flt r1, phi, theta;
r1=sqrt(pnt.x*pnt.x + pnt.y*pnt.y + pnt.z*pnt.z);
phi=acos(-pnt.y/r1);
*v=phi/3.1415926;
theta=acos((pnt.x/r1)/sin(phi))/TWOPI;
if (pnt.z > 0.0)
*u = theta;
else
*u = 1 - theta;
}

View File

@@ -0,0 +1,56 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
The original source for this example is
Copyright (c) 1994-2008 John E. Stone
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/*
* coordsys.h - defines for coordinate system routines.
*
* $Id: coordsys.h,v 1.2 2007-02-22 17:54:15 Exp $
*/
#define TWOPI 6.2831853
void xytopolar(flt, flt, flt, flt *, flt *);
void xyztocyl(vector, flt, flt *, flt *);
void xyztospr(vector, flt *, flt *);

View File

@@ -0,0 +1,267 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
The original source for this example is
Copyright (c) 1994-2008 John E. Stone
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/*
* cylinder.cpp - This file contains the functions for dealing with cylinders.
*/
#include "machine.h"
#include "types.h"
#include "macros.h"
#include "vector.h"
#include "intersect.h"
#include "util.h"
#define CYLINDER_PRIVATE
#include "cylinder.h"
static object_methods cylinder_methods = {
(void (*)(void *, void *))(cylinder_intersect),
(void (*)(void *, void *, void *, void *))(cylinder_normal),
cylinder_bbox,
free
};
static object_methods fcylinder_methods = {
(void (*)(void *, void *))(fcylinder_intersect),
(void (*)(void *, void *, void *, void *))(cylinder_normal),
fcylinder_bbox,
free
};
object * newcylinder(void * tex, vector ctr, vector axis, flt rad) {
cylinder * c;
c=(cylinder *) rt_getmem(sizeof(cylinder));
memset(c, 0, sizeof(cylinder));
c->methods = &cylinder_methods;
c->tex=(texture *) tex;
c->ctr=ctr;
c->axis=axis;
c->rad=rad;
return (object *) c;
}
static int cylinder_bbox(void * obj, vector * min, vector * max) {
return 0; /* infinite / unbounded object */
}
static void cylinder_intersect(cylinder * cyl, ray * ry) {
vector rc, n, D, O;
flt t, s, tin, tout, ln, d;
rc.x = ry->o.x - cyl->ctr.x;
rc.y = ry->o.y - cyl->ctr.y;
rc.z = ry->o.z - cyl->ctr.z;
VCross(&ry->d, &cyl->axis, &n);
VDOT(ln, n, n);
ln=sqrt(ln); /* finish length calculation */
if (ln == 0.0) { /* ray is parallel to the cylinder.. */
VDOT(d, rc, cyl->axis);
D.x = rc.x - d * cyl->axis.x;
D.y = rc.y - d * cyl->axis.y;
D.z = rc.z - d * cyl->axis.z;
VDOT(d, D, D);
d = sqrt(d);
tin = -FHUGE;
tout = FHUGE;
/* if (d <= cyl->rad) then ray is inside cylinder.. else outside */
}
VNorm(&n);
VDOT(d, rc, n);
d = fabs(d);
if (d <= cyl->rad) { /* ray intersects cylinder.. */
VCross(&rc, &cyl->axis, &O);
VDOT(t, O, n);
t = - t / ln;
VCross(&n, &cyl->axis, &O);
VNorm(&O);
VDOT(s, ry->d, O);
s = fabs(sqrt(cyl->rad*cyl->rad - d*d) / s);
tin = t - s;
add_intersection(tin, (object *) cyl, ry);
tout = t + s;
add_intersection(tout, (object *) cyl, ry);
}
}
static void cylinder_normal(cylinder * cyl, vector * pnt, ray * incident, vector * N) {
vector a,b,c;
flt t;
VSub((vector *) pnt, &(cyl->ctr), &a);
c=cyl->axis;
VNorm(&c);
VDOT(t, a, c);
b.x = c.x * t + cyl->ctr.x;
b.y = c.y * t + cyl->ctr.y;
b.z = c.z * t + cyl->ctr.z;
VSub(pnt, &b, N);
VNorm(N);
if (VDot(N, &(incident->d)) > 0.0) { /* make cylinder double sided */
N->x=-N->x;
N->y=-N->y;
N->z=-N->z;
}
}
object * newfcylinder(void * tex, vector ctr, vector axis, flt rad) {
cylinder * c;
c=(cylinder *) rt_getmem(sizeof(cylinder));
memset(c, 0, sizeof(cylinder));
c->methods = &fcylinder_methods;
c->tex=(texture *) tex;
c->ctr=ctr;
c->axis=axis;
c->rad=rad;
return (object *) c;
}
static int fcylinder_bbox(void * obj, vector * min, vector * max) {
cylinder * c = (cylinder *) obj;
vector mintmp, maxtmp;
mintmp.x = c->ctr.x;
mintmp.y = c->ctr.y;
mintmp.z = c->ctr.z;
maxtmp.x = c->ctr.x + c->axis.x;
maxtmp.y = c->ctr.y + c->axis.y;
maxtmp.z = c->ctr.z + c->axis.z;
min->x = MYMIN(mintmp.x, maxtmp.x);
min->y = MYMIN(mintmp.y, maxtmp.y);
min->z = MYMIN(mintmp.z, maxtmp.z);
min->x -= c->rad;
min->y -= c->rad;
min->z -= c->rad;
max->x = MYMAX(mintmp.x, maxtmp.x);
max->y = MYMAX(mintmp.y, maxtmp.y);
max->z = MYMAX(mintmp.z, maxtmp.z);
max->x += c->rad;
max->y += c->rad;
max->z += c->rad;
return 1;
}
static void fcylinder_intersect(cylinder * cyl, ray * ry) {
vector rc, n, O, hit, tmp2, ctmp4;
flt t, s, tin, tout, ln, d, tmp, tmp3;
rc.x = ry->o.x - cyl->ctr.x;
rc.y = ry->o.y - cyl->ctr.y;
rc.z = ry->o.z - cyl->ctr.z;
VCross(&ry->d, &cyl->axis, &n);
VDOT(ln, n, n);
ln=sqrt(ln); /* finish length calculation */
if (ln == 0.0) { /* ray is parallel to the cylinder.. */
return; /* in this case, we want to miss or go through the "hole" */
}
VNorm(&n);
VDOT(d, rc, n);
d = fabs(d);
if (d <= cyl->rad) { /* ray intersects cylinder.. */
VCross(&rc, &cyl->axis, &O);
VDOT(t, O, n);
t = - t / ln;
VCross(&n, &cyl->axis, &O);
VNorm(&O);
VDOT(s, ry->d, O);
s = fabs(sqrt(cyl->rad*cyl->rad - d*d) / s);
tin = t - s;
RAYPNT(hit, (*ry), tin);
ctmp4=cyl->axis;
VNorm(&ctmp4);
tmp2.x = hit.x - cyl->ctr.x;
tmp2.y = hit.y - cyl->ctr.y;
tmp2.z = hit.z - cyl->ctr.z;
VDOT(tmp, tmp2, ctmp4);
VDOT(tmp3, cyl->axis, cyl->axis);
if ((tmp > 0.0) && (tmp < sqrt(tmp3)))
add_intersection(tin, (object *) cyl, ry);
tout = t + s;
RAYPNT(hit, (*ry), tout);
tmp2.x = hit.x - cyl->ctr.x;
tmp2.y = hit.y - cyl->ctr.y;
tmp2.z = hit.z - cyl->ctr.z;
VDOT(tmp, tmp2, ctmp4);
VDOT(tmp3, cyl->axis, cyl->axis);
if ((tmp > 0.0) && (tmp < sqrt(tmp3)))
add_intersection(tout, (object *) cyl, ry);
}
}

View File

@@ -0,0 +1,74 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
The original source for this example is
Copyright (c) 1994-2008 John E. Stone
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/*
* cylinder.h - This file contains the defines for cylinders etc.
*
* $Id: cylinder.h,v 1.2 2007-02-22 17:54:15 Exp $
*/
object * newcylinder(void *, vector, vector, flt);
object * newfcylinder(void *, vector, vector, flt);
#ifdef CYLINDER_PRIVATE
typedef struct {
unsigned int id; /* Unique Object serial number */
void * nextobj; /* pointer to next object in list */
object_methods * methods; /* this object's methods */
texture * tex; /* object texture */
vector ctr;
vector axis;
flt rad;
} cylinder;
static void cylinder_intersect(cylinder *, ray *);
static void fcylinder_intersect(cylinder *, ray *);
static int cylinder_bbox(void * obj, vector * min, vector * max);
static int fcylinder_bbox(void * obj, vector * min, vector * max);
static void cylinder_normal(cylinder *, vector *, ray *, vector *);
#endif

View File

@@ -0,0 +1,307 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
The original source for this example is
Copyright (c) 1994-2008 John E. Stone
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/*
* extvol.cpp - Volume rendering helper routines etc.
*/
#include<stdio.h>
#include "machine.h"
#include "types.h"
#include "macros.h"
#include "vector.h"
#include "util.h"
#include "box.h"
#include "extvol.h"
#include "trace.h"
#include "sphere.h"
#include "light.h"
#include "shade.h"
#include "global.h"
int extvol_bbox(void * obj, vector * min, vector * max) {
box * b = (box *) obj;
*min = b->min;
*max = b->max;
return 1;
}
static object_methods extvol_methods = {
(void (*)(void *, void *))(box_intersect),
(void (*)(void *, void *, void *, void *))(box_normal),
extvol_bbox,
free
};
extvol * newextvol(void * voidtex, vector min, vector max,
int samples, flt (* evaluator)(flt, flt, flt)) {
extvol * xvol;
texture * tex;
tex = (texture *) voidtex;
xvol = (extvol *) rt_getmem(sizeof(extvol));
memset(xvol, 0, sizeof(extvol));
xvol->methods = &extvol_methods;
xvol->min=min;
xvol->max=max;
xvol->evaluator = evaluator;
xvol->ambient = tex->ambient;
xvol->diffuse = tex->diffuse;
xvol->opacity = tex->opacity;
xvol->samples = samples;
xvol->tex = (texture *)rt_getmem(sizeof(texture));
memset(xvol->tex, 0, sizeof(texture));
xvol->tex->ctr.x = 0.0;
xvol->tex->ctr.y = 0.0;
xvol->tex->ctr.z = 0.0;
xvol->tex->rot = xvol->tex->ctr;
xvol->tex->scale = xvol->tex->ctr;
xvol->tex->uaxs = xvol->tex->ctr;
xvol->tex->vaxs = xvol->tex->ctr;
xvol->tex->islight = 0;
xvol->tex->shadowcast = 0;
xvol->tex->col=tex->col;
xvol->tex->ambient=1.0;
xvol->tex->diffuse=0.0;
xvol->tex->specular=0.0;
xvol->tex->opacity=1.0;
xvol->tex->img=NULL;
xvol->tex->texfunc=(color(*)(void *, void *, void *))(ext_volume_texture);
xvol->tex->obj = (void *) xvol; /* XXX hack! */
return xvol;
}
color ExtVoxelColor(flt scalar) {
color col;
if (scalar > 1.0)
scalar = 1.0;
if (scalar < 0.0)
scalar = 0.0;
if (scalar < 0.5) {
col.g = 0.0;
}
else {
col.g = (scalar - 0.5) * 2.0;
}
col.r = scalar;
col.b = 1.0 - (scalar / 2.0);
return col;
}
color ext_volume_texture(vector * hit, texture * tex, ray * ry) {
color col, col2;
box * bx;
extvol * xvol;
flt a, tx1, tx2, ty1, ty2, tz1, tz2;
flt tnear, tfar;
flt t, tdist, dt, ddt, sum, tt;
vector pnt, bln;
flt scalar, transval;
int i;
point_light * li;
color diffint;
vector N, L;
flt inten;
col.r = 0.0;
col.g = 0.0;
col.b = 0.0;
bx = (box *) tex->obj;
xvol = (extvol *) tex->obj;
tnear= -FHUGE;
tfar= FHUGE;
if (ry->d.x == 0.0) {
if ((ry->o.x < bx->min.x) || (ry->o.x > bx->max.x)) return col;
}
else {
tx1 = (bx->min.x - ry->o.x) / ry->d.x;
tx2 = (bx->max.x - ry->o.x) / ry->d.x;
if (tx1 > tx2) { a=tx1; tx1=tx2; tx2=a; }
if (tx1 > tnear) tnear=tx1;
if (tx2 < tfar) tfar=tx2;
}
if (tnear > tfar) return col;
if (tfar < 0.0) return col;
if (ry->d.y == 0.0) {
if ((ry->o.y < bx->min.y) || (ry->o.y > bx->max.y)) return col;
}
else {
ty1 = (bx->min.y - ry->o.y) / ry->d.y;
ty2 = (bx->max.y - ry->o.y) / ry->d.y;
if (ty1 > ty2) { a=ty1; ty1=ty2; ty2=a; }
if (ty1 > tnear) tnear=ty1;
if (ty2 < tfar) tfar=ty2;
}
if (tnear > tfar) return col;
if (tfar < 0.0) return col;
if (ry->d.z == 0.0) {
if ((ry->o.z < bx->min.z) || (ry->o.z > bx->max.z)) return col;
}
else {
tz1 = (bx->min.z - ry->o.z) / ry->d.z;
tz2 = (bx->max.z - ry->o.z) / ry->d.z;
if (tz1 > tz2) { a=tz1; tz1=tz2; tz2=a; }
if (tz1 > tnear) tnear=tz1;
if (tz2 < tfar) tfar=tz2;
}
if (tnear > tfar) return col;
if (tfar < 0.0) return col;
if (tnear < 0.0) tnear=0.0;
tdist = xvol->samples;
tt = (xvol->opacity / tdist);
bln.x=fabs(bx->min.x - bx->max.x);
bln.y=fabs(bx->min.y - bx->max.y);
bln.z=fabs(bx->min.z - bx->max.z);
dt = 1.0 / tdist;
sum = 0.0;
/* Accumulate color as the ray passes through the voxels */
for (t=tnear; t<=tfar; t+=dt) {
if (sum < 1.0) {
pnt.x=((ry->o.x + (ry->d.x * t)) - bx->min.x) / bln.x;
pnt.y=((ry->o.y + (ry->d.y * t)) - bx->min.y) / bln.y;
pnt.z=((ry->o.z + (ry->d.z * t)) - bx->min.z) / bln.z;
/* call external evaluator assume 0.0 -> 1.0 range.. */
scalar = xvol->evaluator(pnt.x, pnt.y, pnt.z);
transval = tt * scalar;
sum += transval;
col2 = ExtVoxelColor(scalar);
col.r += transval * col2.r * xvol->ambient;
col.g += transval * col2.g * xvol->ambient;
col.b += transval * col2.b * xvol->ambient;
ddt = dt;
/* Add in diffuse shaded light sources (no shadows) */
if (xvol->diffuse > 0.0) {
/* Calculate the Volume gradient at the voxel */
N.x = (xvol->evaluator(pnt.x - ddt, pnt.y, pnt.z) -
xvol->evaluator(pnt.x + ddt, pnt.y, pnt.z)) * 8.0 * tt;
N.y = (xvol->evaluator(pnt.x, pnt.y - ddt, pnt.z) -
xvol->evaluator(pnt.x, pnt.y + ddt, pnt.z)) * 8.0 * tt;
N.z = (xvol->evaluator(pnt.x, pnt.y, pnt.z - ddt) -
xvol->evaluator(pnt.x, pnt.y, pnt.z + ddt)) * 8.0 * tt;
/* only light surfaces with enough of a normal.. */
if ((N.x*N.x + N.y*N.y + N.z*N.z) > 0.0) {
diffint.r = 0.0;
diffint.g = 0.0;
diffint.b = 0.0;
/* add the contribution of each of the lights.. */
for (i=0; i<numlights; i++) {
li=lightlist[i];
VSUB(li->ctr, (*hit), L)
VNorm(&L);
VDOT(inten, N, L)
/* only add light if its from the front of the surface */
/* could add back-lighting if we wanted to later.. */
if (inten > 0.0) {
diffint.r += inten*li->tex->col.r;
diffint.g += inten*li->tex->col.g;
diffint.b += inten*li->tex->col.b;
}
}
col.r += col2.r * diffint.r * xvol->diffuse;
col.g += col2.g * diffint.g * xvol->diffuse;
col.b += col2.b * diffint.b * xvol->diffuse;
}
}
}
else {
sum=1.0;
}
}
/* Add in transmitted ray from outside environment */
if (sum < 1.0) { /* spawn transmission rays / refraction */
color transcol;
transcol = shade_transmission(ry, hit, 1.0 - sum);
col.r += transcol.r; /* add the transmitted ray */
col.g += transcol.g; /* to the diffuse and */
col.b += transcol.b; /* transmission total.. */
}
return col;
}

View File

@@ -0,0 +1,69 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
The original source for this example is
Copyright (c) 1994-2008 John E. Stone
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/*
* vol.h - Volume rendering definitions etc.
*
*
* $Id: extvol.h,v 1.2 2007-02-22 17:54:15 Exp $
*/
typedef struct {
unsigned int id; /* Unique Object serial number */
void * nextobj; /* pointer to next object in list */
object_methods * methods; /* this object's methods */
texture * tex; /* object texture */
vector min;
vector max;
flt ambient;
flt diffuse;
flt opacity;
int samples;
flt (* evaluator)(flt, flt, flt);
} extvol;
extvol * newextvol(void * voidtex, vector min, vector max,
int samples, flt (* evaluator)(flt, flt, flt));
color ext_volume_texture(vector *, texture *, ray *);

View File

@@ -0,0 +1,70 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
The original source for this example is
Copyright (c) 1994-2008 John E. Stone
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/*
* global.cpp - any/all global data items etc should be in this file
*/
#include "types.h"
#include "machine.h"
#include "sphere.h"
#include "light.h"
/* stuff moved from intersect.c */
object * rootobj = NULL; /* starts out empty. */
point_light * lightlist[MAXLIGHTS];
int numlights = 0;
unsigned int numobjects = 0; /* used to assign unique object ID's */
/* used in util.c */
unsigned int rt_mem_in_use = 0;
/* used in api.c */
int parinitted = 0;
int graphicswindowopen = 0;

View File

@@ -0,0 +1,64 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
The original source for this example is
Copyright (c) 1994-2008 John E. Stone
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/*
* global.h - any/all global data items etc should be in this file
*
* $Id: global.h,v 1.2 2007-02-22 17:54:15 Exp $
*
*/
/* stuff moved from intersect.c */
extern object * rootobj;
extern point_light * lightlist[MAXLIGHTS];
extern int numlights;
extern unsigned int numobjects;
extern unsigned int rt_mem_in_use;
extern int parinitted;
extern int graphicswindowopen;

View File

@@ -0,0 +1,675 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
The original source for this example is
Copyright (c) 1994-2008 John E. Stone
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/*
* grid.cpp - spatial subdivision efficiency structures
*/
#include "machine.h"
#include "types.h"
#include "macros.h"
#include "vector.h"
#include "intersect.h"
#include "util.h"
#define GRID_PRIVATE
#include "grid.h"
#ifndef cbrt
#define cbrt(x) ((x) > 0.0 ? pow((double)(x), 1.0/3.0) : \
((x) < 0.0 ? -pow((double)-(x), 1.0/3.0) : 0.0))
#define qbrt(x) ((x) > 0.0 ? pow((double)(x), 1.0/4.0) : \
((x) < 0.0 ? -pow((double)-(x), 1.0/4.0) : 0.0))
#endif
static object_methods grid_methods = {
(void (*)(void *, void *))(grid_intersect),
(void (*)(void *, void *, void *, void *))(NULL),
grid_bbox,
grid_free
};
extern bool silent_mode;
object * newgrid(int xsize, int ysize, int zsize, vector min, vector max) {
grid * g;
g = (grid *) rt_getmem(sizeof(grid));
memset(g, 0, sizeof(grid));
g->methods = &grid_methods;
g->id = new_objectid();
g->xsize = xsize;
g->ysize = ysize;
g->zsize = zsize;
g->min = min;
g->max = max;
VSub(&g->max, &g->min, &g->voxsize);
g->voxsize.x /= (flt) g->xsize;
g->voxsize.y /= (flt) g->ysize;
g->voxsize.z /= (flt) g->zsize;
g->cells = (objectlist **) rt_getmem(xsize*ysize*zsize*sizeof(objectlist *));
memset(g->cells, 0, xsize*ysize*zsize * sizeof(objectlist *));
/* fprintf(stderr, "New grid, size: %8d %8d %8d\n", g->xsize, g->ysize, g->zsize); */
return (object *) g;
}
static int grid_bbox(void * obj, vector * min, vector * max) {
grid * g = (grid *) obj;
*min = g->min;
*max = g->max;
return 1;
}
static void grid_free(void * v) {
int i, numvoxels;
grid * g = (grid *) v;
/* loop through all voxels and free the object lists */
numvoxels = g->xsize * g->ysize * g->zsize;
for (i=0; i<numvoxels; i++) {
objectlist * lcur, * lnext;
lcur = g->cells[i];
while (lcur != NULL) {
lnext = lcur->next;
free(lcur);
}
}
/* free the grid cells */
free(g->cells);
/* free all objects on the grid object list */
free_objects(g->objects);
free(g);
}
static void globalbound(object ** rootlist, vector * gmin, vector * gmax) {
vector min, max;
object * cur;
if (*rootlist == NULL) /* don't bound non-existent objects */
return;
gmin->x = FHUGE; gmin->y = FHUGE; gmin->z = FHUGE;
gmax->x = -FHUGE; gmax->y = -FHUGE; gmax->z = -FHUGE;
cur=*rootlist;
while (cur != NULL) { /* Go! */
min.x = -FHUGE; min.y = -FHUGE; min.z = -FHUGE;
max.x = FHUGE; max.y = FHUGE; max.z = FHUGE;
if (cur->methods->bbox((void *) cur, &min, &max)) {
gmin->x = MYMIN( gmin->x , min.x);
gmin->y = MYMIN( gmin->y , min.y);
gmin->z = MYMIN( gmin->z , min.z);
gmax->x = MYMAX( gmax->x , max.x);
gmax->y = MYMAX( gmax->y , max.y);
gmax->z = MYMAX( gmax->z , max.z);
}
cur=(object *)cur->nextobj;
}
}
static int cellbound(grid *g, gridindex *index, vector * cmin, vector * cmax) {
vector min, max, cellmin, cellmax;
objectlist * cur;
int numinbounds = 0;
cur = g->cells[index->z*g->xsize*g->ysize + index->y*g->xsize + index->x];
if (cur == NULL) /* don't bound non-existent objects */
return 0;
cellmin.x = voxel2x(g, index->x);
cellmin.y = voxel2y(g, index->y);
cellmin.z = voxel2z(g, index->z);
cellmax.x = cellmin.x + g->voxsize.x;
cellmax.y = cellmin.y + g->voxsize.y;
cellmax.z = cellmin.z + g->voxsize.z;
cmin->x = FHUGE; cmin->y = FHUGE; cmin->z = FHUGE;
cmax->x = -FHUGE; cmax->y = -FHUGE; cmax->z = -FHUGE;
while (cur != NULL) { /* Go! */
min.x = -FHUGE; min.y = -FHUGE; min.z = -FHUGE;
max.x = FHUGE; max.y = FHUGE; max.z = FHUGE;
if (cur->obj->methods->bbox((void *) cur->obj, &min, &max)) {
if ((min.x >= cellmin.x) && (max.x <= cellmax.x) &&
(min.y >= cellmin.y) && (max.y <= cellmax.y) &&
(min.z >= cellmin.z) && (max.z <= cellmax.z)) {
cmin->x = MYMIN( cmin->x , min.x);
cmin->y = MYMIN( cmin->y , min.y);
cmin->z = MYMIN( cmin->z , min.z);
cmax->x = MYMAX( cmax->x , max.x);
cmax->y = MYMAX( cmax->y , max.y);
cmax->z = MYMAX( cmax->z , max.z);
numinbounds++;
}
}
cur=cur->next;
}
/* in case we get a 0.0 sized axis on the cell bounds, we'll */
/* use the original cell bounds */
if ((cmax->x - cmin->x) < EPSILON) {
cmax->x += EPSILON;
cmin->x -= EPSILON;
}
if ((cmax->y - cmin->y) < EPSILON) {
cmax->y += EPSILON;
cmin->y -= EPSILON;
}
if ((cmax->z - cmin->z) < EPSILON) {
cmax->z += EPSILON;
cmin->z -= EPSILON;
}
return numinbounds;
}
static int countobj(object * root) {
object * cur; /* counts the number of objects on a list */
int numobj;
numobj=0;
cur=root;
while (cur != NULL) {
cur=(object *)cur->nextobj;
numobj++;
}
return numobj;
}
static int countobjlist(objectlist * root) {
objectlist * cur;
int numobj;
numobj=0;
cur = root;
while (cur != NULL) {
cur = cur->next;
numobj++;
}
return numobj;
}
int engrid_scene(object ** list) {
grid * g;
int numobj, numcbrt;
vector gmin, gmax;
gridindex index;
if (*list == NULL)
return 0;
numobj = countobj(*list);
if ( !silent_mode )
fprintf(stderr, "Scene contains %d bounded objects.\n", numobj);
if (numobj > 16) {
numcbrt = (int) cbrt(4*numobj);
globalbound(list, &gmin, &gmax);
g = (grid *) newgrid(numcbrt, numcbrt, numcbrt, gmin, gmax);
engrid_objlist(g, list);
numobj = countobj(*list);
g->nextobj = *list;
*list = (object *) g;
/* now create subgrids.. */
for (index.z=0; index.z<g->zsize; index.z++) {
for (index.y=0; index.y<g->ysize; index.y++) {
for (index.x=0; index.x<g->xsize; index.x++) {
engrid_cell(g, &index);
}
}
}
}
return 1;
}
void engrid_objlist(grid * g, object ** list) {
object * cur, * next, **prev;
if (*list == NULL)
return;
prev = list;
cur = *list;
while (cur != NULL) {
next = (object *)cur->nextobj;
if (engrid_object(g, cur))
*prev = next;
else
prev = (object **) &cur->nextobj;
cur = next;
}
}
static int engrid_cell(grid * gold, gridindex *index) {
vector gmin, gmax, gsize;
flt len;
int numobj, numcbrt, xs, ys, zs;
grid * g;
objectlist **list;
objectlist * newobj;
list = &gold->cells[index->z*gold->xsize*gold->ysize +
index->y*gold->xsize + index->x];
if (*list == NULL)
return 0;
numobj = cellbound(gold, index, &gmin, &gmax);
VSub(&gmax, &gmin, &gsize);
len = 1.0 / (MYMAX( MYMAX(gsize.x, gsize.y), gsize.z ));
gsize.x *= len;
gsize.y *= len;
gsize.z *= len;
if (numobj > 16) {
numcbrt = (int) cbrt(2*numobj);
xs = (int) ((flt) numcbrt * gsize.x);
if (xs < 1) xs = 1;
ys = (int) ((flt) numcbrt * gsize.y);
if (ys < 1) ys = 1;
zs = (int) ((flt) numcbrt * gsize.z);
if (zs < 1) zs = 1;
g = (grid *) newgrid(xs, ys, zs, gmin, gmax);
engrid_objectlist(g, list);
newobj = (objectlist *) rt_getmem(sizeof(objectlist));
newobj->obj = (object *) g;
newobj->next = *list;
*list = newobj;
g->nextobj = gold->objects;
gold->objects = (object *) g;
}
return 1;
}
static int engrid_objectlist(grid * g, objectlist ** list) {
objectlist * cur, * next, **prev;
int numsucceeded = 0;
if (*list == NULL)
return 0;
prev = list;
cur = *list;
while (cur != NULL) {
next = cur->next;
if (engrid_object(g, cur->obj)) {
*prev = next;
free(cur);
numsucceeded++;
}
else {
prev = &cur->next;
}
cur = next;
}
return numsucceeded;
}
static int engrid_object(grid * g, object * obj) {
vector omin, omax;
gridindex low, high;
int x, y, z, zindex, yindex, voxindex;
objectlist * tmp;
if (obj->methods->bbox(obj, &omin, &omax)) {
if (!pos2grid(g, &omin, &low) || !pos2grid(g, &omax, &high)) {
return 0; /* object is not wholly contained in the grid */
}
}
else {
return 0; /* object is unbounded */
}
/* add the object to the complete list of objects in the grid */
obj->nextobj = g->objects;
g->objects = obj;
/* add this object to all voxels it inhabits */
for (z=low.z; z<=high.z; z++) {
zindex = z * g->xsize * g->ysize;
for (y=low.y; y<=high.y; y++) {
yindex = y * g->xsize;
for (x=low.x; x<=high.x; x++) {
voxindex = x + yindex + zindex;
tmp = (objectlist *) rt_getmem(sizeof(objectlist));
tmp->next = g->cells[voxindex];
tmp->obj = obj;
g->cells[voxindex] = tmp;
}
}
}
return 1;
}
static int pos2grid(grid * g, vector * pos, gridindex * index) {
index->x = (int) ((pos->x - g->min.x) / g->voxsize.x);
index->y = (int) ((pos->y - g->min.y) / g->voxsize.y);
index->z = (int) ((pos->z - g->min.z) / g->voxsize.z);
if (index->x == g->xsize)
index->x--;
if (index->y == g->ysize)
index->y--;
if (index->z == g->zsize)
index->z--;
if (index->x < 0 || index->x > g->xsize ||
index->y < 0 || index->y > g->ysize ||
index->z < 0 || index->z > g->zsize)
return 0;
if (pos->x < g->min.x || pos->x > g->max.x ||
pos->y < g->min.y || pos->y > g->max.y ||
pos->z < g->min.z || pos->z > g->max.z)
return 0;
return 1;
}
/* the real thing */
static void grid_intersect(grid * g, ray * ry) {
flt tnear, tfar, offset;
vector curpos, tmax, tdelta, pdeltaX, pdeltaY, pdeltaZ, nXp, nYp, nZp;
gridindex curvox, step, out;
int voxindex;
objectlist * cur;
if (ry->flags & RT_RAY_FINISHED)
return;
if (!grid_bounds_intersect(g, ry, &tnear, &tfar))
return;
if (ry->maxdist < tnear)
return;
curpos = Raypnt(ry, tnear);
pos2grid(g, &curpos, &curvox);
offset = tnear;
/* Setup X iterator stuff */
if (fabs(ry->d.x) < EPSILON) {
tmax.x = FHUGE;
tdelta.x = 0.0;
step.x = 0;
out.x = 0; /* never goes out of bounds on this axis */
}
else if (ry->d.x < 0.0) {
tmax.x = offset + ((voxel2x(g, curvox.x) - curpos.x) / ry->d.x);
tdelta.x = g->voxsize.x / - ry->d.x;
step.x = out.x = -1;
}
else {
tmax.x = offset + ((voxel2x(g, curvox.x + 1) - curpos.x) / ry->d.x);
tdelta.x = g->voxsize.x / ry->d.x;
step.x = 1;
out.x = g->xsize;
}
/* Setup Y iterator stuff */
if (fabs(ry->d.y) < EPSILON) {
tmax.y = FHUGE;
tdelta.y = 0.0;
step.y = 0;
out.y = 0; /* never goes out of bounds on this axis */
}
else if (ry->d.y < 0.0) {
tmax.y = offset + ((voxel2y(g, curvox.y) - curpos.y) / ry->d.y);
tdelta.y = g->voxsize.y / - ry->d.y;
step.y = out.y = -1;
}
else {
tmax.y = offset + ((voxel2y(g, curvox.y + 1) - curpos.y) / ry->d.y);
tdelta.y = g->voxsize.y / ry->d.y;
step.y = 1;
out.y = g->ysize;
}
/* Setup Z iterator stuff */
if (fabs(ry->d.z) < EPSILON) {
tmax.z = FHUGE;
tdelta.z = 0.0;
step.z = 0;
out.z = 0; /* never goes out of bounds on this axis */
}
else if (ry->d.z < 0.0) {
tmax.z = offset + ((voxel2z(g, curvox.z) - curpos.z) / ry->d.z);
tdelta.z = g->voxsize.z / - ry->d.z;
step.z = out.z = -1;
}
else {
tmax.z = offset + ((voxel2z(g, curvox.z + 1) - curpos.z) / ry->d.z);
tdelta.z = g->voxsize.z / ry->d.z;
step.z = 1;
out.z = g->zsize;
}
pdeltaX = ry->d;
VScale(&pdeltaX, tdelta.x);
pdeltaY = ry->d;
VScale(&pdeltaY, tdelta.y);
pdeltaZ = ry->d;
VScale(&pdeltaZ, tdelta.z);
nXp = Raypnt(ry, tmax.x);
nYp = Raypnt(ry, tmax.y);
nZp = Raypnt(ry, tmax.z);
voxindex = curvox.z*g->xsize*g->ysize + curvox.y*g->xsize + curvox.x;
while (1) {
if (tmax.x < tmax.y && tmax.x < tmax.z) {
cur = g->cells[voxindex];
while (cur != NULL) {
if (ry->mbox[cur->obj->id] != ry->serial) {
ry->mbox[cur->obj->id] = ry->serial;
cur->obj->methods->intersect(cur->obj, ry);
}
cur = cur->next;
}
curvox.x += step.x;
if (ry->maxdist < tmax.x || curvox.x == out.x)
break;
voxindex += step.x;
tmax.x += tdelta.x;
curpos = nXp;
nXp.x += pdeltaX.x;
nXp.y += pdeltaX.y;
nXp.z += pdeltaX.z;
}
else if (tmax.z < tmax.y) {
cur = g->cells[voxindex];
while (cur != NULL) {
if (ry->mbox[cur->obj->id] != ry->serial) {
ry->mbox[cur->obj->id] = ry->serial;
cur->obj->methods->intersect(cur->obj, ry);
}
cur = cur->next;
}
curvox.z += step.z;
if (ry->maxdist < tmax.z || curvox.z == out.z)
break;
voxindex += step.z*g->xsize*g->ysize;
tmax.z += tdelta.z;
curpos = nZp;
nZp.x += pdeltaZ.x;
nZp.y += pdeltaZ.y;
nZp.z += pdeltaZ.z;
}
else {
cur = g->cells[voxindex];
while (cur != NULL) {
if (ry->mbox[cur->obj->id] != ry->serial) {
ry->mbox[cur->obj->id] = ry->serial;
cur->obj->methods->intersect(cur->obj, ry);
}
cur = cur->next;
}
curvox.y += step.y;
if (ry->maxdist < tmax.y || curvox.y == out.y)
break;
voxindex += step.y*g->xsize;
tmax.y += tdelta.y;
curpos = nYp;
nYp.x += pdeltaY.x;
nYp.y += pdeltaY.y;
nYp.z += pdeltaY.z;
}
if (ry->flags & RT_RAY_FINISHED)
break;
}
}
static void voxel_intersect(grid * g, ray * ry, int voxindex) {
objectlist * cur;
cur = g->cells[voxindex];
while (cur != NULL) {
cur->obj->methods->intersect(cur->obj, ry);
cur = cur->next;
}
}
static int grid_bounds_intersect(grid * g, ray * ry, flt *nr, flt *fr) {
flt a, tx1, tx2, ty1, ty2, tz1, tz2;
flt tnear, tfar;
tnear= -FHUGE;
tfar= FHUGE;
if (ry->d.x == 0.0) {
if ((ry->o.x < g->min.x) || (ry->o.x > g->max.x)) return 0;
}
else {
tx1 = (g->min.x - ry->o.x) / ry->d.x;
tx2 = (g->max.x - ry->o.x) / ry->d.x;
if (tx1 > tx2) { a=tx1; tx1=tx2; tx2=a; }
if (tx1 > tnear) tnear=tx1;
if (tx2 < tfar) tfar=tx2;
}
if (tnear > tfar) return 0;
if (tfar < 0.0) return 0;
if (ry->d.y == 0.0) {
if ((ry->o.y < g->min.y) || (ry->o.y > g->max.y)) return 0;
}
else {
ty1 = (g->min.y - ry->o.y) / ry->d.y;
ty2 = (g->max.y - ry->o.y) / ry->d.y;
if (ty1 > ty2) { a=ty1; ty1=ty2; ty2=a; }
if (ty1 > tnear) tnear=ty1;
if (ty2 < tfar) tfar=ty2;
}
if (tnear > tfar) return 0;
if (tfar < 0.0) return 0;
if (ry->d.z == 0.0) {
if ((ry->o.z < g->min.z) || (ry->o.z > g->max.z)) return 0;
}
else {
tz1 = (g->min.z - ry->o.z) / ry->d.z;
tz2 = (g->max.z - ry->o.z) / ry->d.z;
if (tz1 > tz2) { a=tz1; tz1=tz2; tz2=a; }
if (tz1 > tnear) tnear=tz1;
if (tz2 < tfar) tfar=tz2;
}
if (tnear > tfar) return 0;
if (tfar < 0.0) return 0;
*nr = tnear;
*fr = tfar;
return 1;
}

View File

@@ -0,0 +1,116 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
The original source for this example is
Copyright (c) 1994-2008 John E. Stone
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/*
* grid.h - spatial subdivision efficiency structures
*
* $Id: grid.h,v 1.2 2007-02-22 17:54:15 Exp $
*
*/
int engrid_scene(object ** list);
object * newgrid(int xsize, int ysize, int zsize, vector min, vector max);
#ifdef GRID_PRIVATE
typedef struct objectlist {
struct objectlist * next; /* next link in the list */
object * obj; /* the actual object */
} objectlist;
typedef struct {
unsigned int id; /* Unique Object serial number */
void * nextobj; /* pointer to next object in list */
object_methods * methods; /* this object's methods */
texture * tex; /* object texture */
int xsize; /* number of cells along the X direction */
int ysize; /* number of cells along the Y direction */
int zsize; /* number of cells along the Z direction */
vector min; /* the minimum coords for the box containing the grid */
vector max; /* the maximum coords for the box containing the grid */
vector voxsize; /* the size of a grid cell/voxel */
object * objects; /* all objects contained in the grid */
objectlist ** cells; /* the grid cells themselves */
} grid;
typedef struct {
int x; /* Voxel X address */
int y; /* Voxel Y address */
int z; /* Voxel Z address */
} gridindex;
/*
* Convert from voxel number along X/Y/Z to corresponding coordinate.
*/
#define voxel2x(g,X) ((X) * (g->voxsize.x) + (g->min.x))
#define voxel2y(g,Y) ((Y) * (g->voxsize.y) + (g->min.y))
#define voxel2z(g,Z) ((Z) * (g->voxsize.z) + (g->min.z))
/*
* And vice-versa.
*/
#define x2voxel(g,x) (((x) - g->min.x) / g->voxsize.x)
#define y2voxel(g,y) (((y) - g->min.y) / g->voxsize.y)
#define z2voxel(g,z) (((z) - g->min.z) / g->voxsize.z)
static int grid_bbox(void * obj, vector * min, vector * max);
static void grid_free(void * v);
static int cellbound(grid *g, gridindex *index, vector * cmin, vector * cmax);
void engrid_objlist(grid * g, object ** list);
static int engrid_object(grid * g, object * obj);
static int engrid_objectlist(grid * g, objectlist ** list);
static int engrid_cell(grid *, gridindex *);
static int pos2grid(grid * g, vector * pos, gridindex * index);
static void grid_intersect(grid *, ray *);
static void voxel_intersect(grid * g, ray * ry, int voxaddr);
static int grid_bounds_intersect(grid * g, ray * ry, flt *near, flt *far);
#endif

View File

@@ -0,0 +1,143 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
The original source for this example is
Copyright (c) 1994-2008 John E. Stone
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/*
* imageio.cpp - This file deals with reading/writing image files
*/
/* For our puposes, we're interested only in the 3 byte per pixel 24 bit
* truecolor sort of file..
*/
#include <stdio.h>
#include "machine.h"
#include "types.h"
#include "util.h"
#include "imageio.h"
#include "ppm.h" /* PPM files */
#include "tgafile.h" /* Truevision Targa files */
#include "jpeg.h" /* JPEG files */
static
int fakeimage(char * name, int * xres, int * yres, unsigned char ** imgdata) {
int i, imgsize;
fprintf(stderr, "Error loading image %s. Faking it.\n", name);
*xres = 2;
*yres = 2;
imgsize = 3 * (*xres) * (*yres);
*imgdata = (unsigned char *)rt_getmem(imgsize);
for (i=0; i<imgsize; i++) {
(*imgdata)[i] = 255;
}
return IMAGENOERR;
}
int readimage(rawimage * img) {
int rc;
int xres, yres;
unsigned char * imgdata = NULL;
char * name = img->name;
if (strstr(name, ".ppm")) {
rc = readppm(name, &xres, &yres, &imgdata);
}
else if (strstr(name, ".tga")) {
rc = readtga(name, &xres, &yres, &imgdata);
}
else if (strstr(name, ".jpg")) {
rc = readjpeg(name, &xres, &yres, &imgdata);
}
else if (strstr(name, ".gif")) {
rc = IMAGEUNSUP;
}
else if (strstr(name, ".png")) {
rc = IMAGEUNSUP;
}
else if (strstr(name, ".tiff")) {
rc = IMAGEUNSUP;
}
else if (strstr(name, ".rgb")) {
rc = IMAGEUNSUP;
}
else if (strstr(name, ".xpm")) {
rc = IMAGEUNSUP;
}
else {
rc = readppm(name, &xres, &yres, &imgdata);
}
switch (rc) {
case IMAGEREADERR:
fprintf(stderr, "Short read encountered while loading image %s\n", name);
rc = IMAGENOERR; /* remap to non-fatal error */
break;
case IMAGEUNSUP:
fprintf(stderr, "Cannot read unsupported image format for image %s\n", name);
break;
}
/* If the image load failed, create a tiny white colored image to fake it */
/* this allows a scene to render even when a file can't be loaded */
if (rc != IMAGENOERR) {
rc = fakeimage(name, &xres, &yres, &imgdata);
}
/* If we succeeded in loading the image, return it. */
if (rc == IMAGENOERR) {
img->xres = xres;
img->yres = yres;
img->bpp = 3;
img->data = imgdata;
}
return rc;
}

View File

@@ -0,0 +1,61 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
The original source for this example is
Copyright (c) 1994-2008 John E. Stone
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/*
* imageio.h - This file deals with reading/writing image files
*
* $Id: imageio.h,v 1.2 2007-02-22 17:54:15 Exp $
*/
/* For our puposes, we're interested only in the 3 byte per pixel 24 bit
truecolor sort of file.. */
#define IMAGENOERR 0 /* no error */
#define IMAGEBADFILE 1 /* can't find or can't open the file */
#define IMAGEUNSUP 2 /* the image file is an unsupported format */
#define IMAGEALLOCERR 3 /* not enough remaining memory to load this image */
#define IMAGEREADERR 4 /* failed read, short reads etc */
int readimage(rawimage *);

View File

@@ -0,0 +1,164 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
The original source for this example is
Copyright (c) 1994-2008 John E. Stone
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/*
* imap.cpp - This file contains code for doing image map type things.
*/
#include "machine.h"
#include "types.h"
#include "imap.h"
#include "util.h"
#include "imageio.h"
rawimage * imagelist[MAXIMGS];
int numimages;
void ResetImages(void) {
int i;
numimages=0;
for (i=0; i<MAXIMGS; i++) {
imagelist[i]=NULL;
}
}
void LoadImage(rawimage * image) {
if (!image->loaded) {
readimage(image);
image->loaded=1;
}
}
color ImageMap(rawimage * image, flt u, flt v) {
color col, colx, colx2;
flt x,y, px, py;
int x1, x2, y1, y2;
unsigned char * ptr;
unsigned char * ptr2;
if (!image->loaded) {
LoadImage(image);
image->loaded=1;
}
if ((u <= 1.0) && (u >=0.0) && (v <= 1.0) && (v >= 0.0)) {
x=(image->xres - 1.0) * u; /* floating point X location */
y=(image->yres - 1.0) * v; /* floating point Y location */
px = x - ((int) x);
py = y - ((int) y);
x1 = (int) x;
x2 = x1 + 1;
y1 = (int) y;
y2 = y1 + 1;
ptr = image->data + ((image->xres * y1) + x1) * 3;
ptr2 = image->data + ((image->xres * y1) + x2) * 3;
colx.r = (flt) ((flt)ptr[0] + px*((flt)ptr2[0] - (flt) ptr[0])) / 255.0;
colx.g = (flt) ((flt)ptr[1] + px*((flt)ptr2[1] - (flt) ptr[1])) / 255.0;
colx.b = (flt) ((flt)ptr[2] + px*((flt)ptr2[2] - (flt) ptr[2])) / 255.0;
ptr = image->data + ((image->xres * y2) + x1) * 3;
ptr2 = image->data + ((image->xres * y2) + x2) * 3;
colx2.r = ((flt)ptr[0] + px*((flt)ptr2[0] - (flt)ptr[0])) / 255.0;
colx2.g = ((flt)ptr[1] + px*((flt)ptr2[1] - (flt)ptr[1])) / 255.0;
colx2.b = ((flt)ptr[2] + px*((flt)ptr2[2] - (flt)ptr[2])) / 255.0;
col.r = colx.r + py*(colx2.r - colx.r);
col.g = colx.g + py*(colx2.g - colx.g);
col.b = colx.b + py*(colx2.b - colx.b);
}
else {
col.r=0.0;
col.g=0.0;
col.b=0.0;
}
return col;
}
rawimage * AllocateImage(char * filename) {
rawimage * newimage = NULL;
int i, intable;
size_t len;
intable=0;
if (numimages!=0) {
for (i=0; i<numimages; i++) {
if (!strcmp(filename, imagelist[i]->name)) {
newimage=imagelist[i];
intable=1;
}
}
}
if (!intable) {
newimage=(rawimage *)rt_getmem(sizeof(rawimage));
newimage->loaded=0;
newimage->xres=0;
newimage->yres=0;
newimage->bpp=0;
newimage->data=NULL;
len=strlen(filename);
if (len > 80) rtbomb("Filename too long in image map!!");
strcpy(newimage->name, filename);
imagelist[numimages]=newimage; /* add new one to the table */
numimages++; /* increment the number of images */
}
return newimage;
}
void DeallocateImage(rawimage * image) {
image->loaded=0;
rt_freemem(image->data);
}

View File

@@ -0,0 +1,57 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
The original source for this example is
Copyright (c) 1994-2008 John E. Stone
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/*
* imap.h - This file contains defines etc for doing image map type things.
*
* $Id: imap.h,v 1.2 2007-02-22 17:54:15 Exp $
*/
void ResetImage(void);
void LoadImage(rawimage *);
color ImageMap(rawimage *, flt, flt);
rawimage * AllocateImage(char *);
void DeallocateImage(rawimage *);
void ResetImages(void);

Some files were not shown because too many files have changed in this diff Show More