include/serialize.h
author Radek Brich <radek.brich@devl.cz>
Sat, 10 May 2008 14:29:37 +0200
branchpyrit
changeset 95 ca7d4c665531
parent 94 4c8abb8977dc
permissions -rw-r--r--
build script fixes, add ldflags build option update and enhance demos fix bug in 4x grid oversampling warn if writePNG called while compiled without libpng make shapes in ShapeList const and add many other const needed due to snowball effect slightly optimize Camera::makeRayPacket using _mm_shuffle_ps make Vector SIMD vectorization disabled by default (causes problems) fix bug in implicit reflection of transmissive surfaces, when surface's reflection parameter is set to zero
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
94
4c8abb8977dc update README
Radek Brich <radek.brich@devl.cz>
parents: 91
diff changeset
     1
/**
4c8abb8977dc update README
Radek Brich <radek.brich@devl.cz>
parents: 91
diff changeset
     2
 * @file  serialize.h
4c8abb8977dc update README
Radek Brich <radek.brich@devl.cz>
parents: 91
diff changeset
     3
 * @brief Object serialization functions
78
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     4
 *
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     5
 * This file is part of Pyrit Ray Tracer.
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     6
 *
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     7
 * Copyright 2008  Radek Brich
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     8
 *
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     9
 * Permission is hereby granted, free of charge, to any person obtaining a copy
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    10
 * of this software and associated documentation files (the "Software"), to deal
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    11
 * in the Software without restriction, including without limitation the rights
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    12
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    13
 * copies of the Software, and to permit persons to whom the Software is
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    14
 * furnished to do so, subject to the following conditions:
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    15
 *
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    16
 * The above copyright notice and this permission notice shall be included in
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    17
 * all copies or substantial portions of the Software.
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    18
 *
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    19
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    20
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    21
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    22
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    23
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    24
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    25
 * THE SOFTWARE.
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    26
 */
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    27
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    28
#ifndef SERIALIZE_H
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    29
#define SERIALIZE_H
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    30
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    31
#include <map>
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    32
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    33
#include "shapes.h"
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    34
#include "container.h"
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    35
#include "kdtree.h"
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    36
94
4c8abb8977dc update README
Radek Brich <radek.brich@devl.cz>
parents: 91
diff changeset
    37
/**
4c8abb8977dc update README
Radek Brich <radek.brich@devl.cz>
parents: 91
diff changeset
    38
 * Maps pointers to indices
4c8abb8977dc update README
Radek Brich <radek.brich@devl.cz>
parents: 91
diff changeset
    39
 *
4c8abb8977dc update README
Radek Brich <radek.brich@devl.cz>
parents: 91
diff changeset
    40
 * This helps when we are saving objects from random memory places
4c8abb8977dc update README
Radek Brich <radek.brich@devl.cz>
parents: 91
diff changeset
    41
 * to file stream
4c8abb8977dc update README
Radek Brich <radek.brich@devl.cz>
parents: 91
diff changeset
    42
 */
78
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    43
class Indexer
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    44
{
95
ca7d4c665531 build script fixes, add ldflags build option
Radek Brich <radek.brich@devl.cz>
parents: 94
diff changeset
    45
	map <const void *, int> indexmap;
78
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    46
	int index;
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    47
public:
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    48
	Indexer(): indexmap(), index(0) {};
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    49
	void reset() { indexmap.clear(); index = 0; };
94
4c8abb8977dc update README
Radek Brich <radek.brich@devl.cz>
parents: 91
diff changeset
    50
4c8abb8977dc update README
Radek Brich <radek.brich@devl.cz>
parents: 91
diff changeset
    51
	/**
4c8abb8977dc update README
Radek Brich <radek.brich@devl.cz>
parents: 91
diff changeset
    52
	 * Make new index or return number of already indexed object
4c8abb8977dc update README
Radek Brich <radek.brich@devl.cz>
parents: 91
diff changeset
    53
	 * @param[in] o        object for indexation
4c8abb8977dc update README
Radek Brich <radek.brich@devl.cz>
parents: 91
diff changeset
    54
	 * @param[out] retidx  returned index
4c8abb8977dc update README
Radek Brich <radek.brich@devl.cz>
parents: 91
diff changeset
    55
	 * @retval true        if object was found
4c8abb8977dc update README
Radek Brich <radek.brich@devl.cz>
parents: 91
diff changeset
    56
	 * @retval false       if new index was made for the object
4c8abb8977dc update README
Radek Brich <radek.brich@devl.cz>
parents: 91
diff changeset
    57
	 */
95
ca7d4c665531 build script fixes, add ldflags build option
Radek Brich <radek.brich@devl.cz>
parents: 94
diff changeset
    58
	bool get(const void *o, int &retidx);
94
4c8abb8977dc update README
Radek Brich <radek.brich@devl.cz>
parents: 91
diff changeset
    59
95
ca7d4c665531 build script fixes, add ldflags build option
Radek Brich <radek.brich@devl.cz>
parents: 94
diff changeset
    60
	const int &operator[](const void *o) { return indexmap[o]; };
78
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    61
};
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    62
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    63
extern Indexer vertex_index, shape_index;
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    64
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    65
void resetSerializer();
80
907929fa9b59 remove forgotten noise.h includes
Radek Brich <radek.brich@devl.cz>
parents: 78
diff changeset
    66
Shape *loadShape(istream &st, Material *mat);
78
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    67
95
ca7d4c665531 build script fixes, add ldflags build option
Radek Brich <radek.brich@devl.cz>
parents: 94
diff changeset
    68
ostream & operator<<(ostream &st, const Shape &o);
ca7d4c665531 build script fixes, add ldflags build option
Radek Brich <radek.brich@devl.cz>
parents: 94
diff changeset
    69
ostream & operator<<(ostream &st, const Vertex &o);
ca7d4c665531 build script fixes, add ldflags build option
Radek Brich <radek.brich@devl.cz>
parents: 94
diff changeset
    70
ostream & operator<<(ostream &st, const Container &o);
78
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    71
9569e9f35374 move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    72
#endif