Welcome to mirror list, hosted at ThFree Co, Russian Federation.

reader.cpp « intern « pointcache « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 75b93c4eaeb1279dcc9eea19c5c9b25e6516fd16 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/*
 * Copyright 2013, Blender Foundation.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

#include <Alembic/AbcCoreHDF5/ReadWrite.h>
#include <Alembic/Abc/ArchiveInfo.h>

#include "reader.h"
#include "util_path.h"
#include "util_error_handler.h"

extern "C" {
#include "BLI_fileops.h"

#include "DNA_scene_types.h"
}

namespace PTC {

using namespace Abc;

Reader::Reader(Scene *scene, ID *id, PointCache *cache) :
    FrameMapper(scene),
    m_error_handler(0),
    m_scene(scene)
{
	std::string filename = ptc_archive_path(cache, id);
	PTC_SAFE_CALL_BEGIN
	m_archive = IArchive(AbcCoreHDF5::ReadArchive(), filename, Abc::ErrorHandler::kThrowPolicy);
	PTC_SAFE_CALL_END_HANDLER(m_error_handler)
}

Reader::~Reader()
{
	if (m_error_handler)
		delete m_error_handler;
}

void Reader::set_error_handler(ErrorHandler *handler)
{
	if (m_error_handler)
		delete m_error_handler;
	
	m_error_handler = handler;
}

bool Reader::valid() const
{
	return m_error_handler ? m_error_handler->max_error_level() >= PTC_ERROR_CRITICAL : true;
}

void Reader::get_frame_range(int &start_frame, int &end_frame)
{
	if (m_archive.valid()) {
		double start_time, end_time;
		GetArchiveStartAndEndTime(m_archive, start_time, end_time);
		start_frame = (int)time_to_frame(start_time);
		end_frame = (int)time_to_frame(end_time);
	}
	else {
		start_frame = end_frame = 1;
	}
}

ISampleSelector Reader::get_frame_sample_selector(float frame)
{
	return ISampleSelector(frame_to_time(frame), ISampleSelector::kFloorIndex);
}

PTCReadSampleResult Reader::test_sample(float frame)
{
	if (m_archive.valid()) {
		double start_time, end_time;
		GetArchiveStartAndEndTime(m_archive, start_time, end_time);
		float start_frame = time_to_frame(start_time);
		float end_frame = time_to_frame(end_time);
		
		if (frame < start_frame)
			return PTC_READ_SAMPLE_EARLY;
		else if (frame > end_frame)
			return PTC_READ_SAMPLE_LATE;
		else {
			/* TODO could also be EXACT, but INTERPOLATED is more general
			 * do we need to support this?
			 * checking individual time samplings is also possible, but more involved.
			 */
			return PTC_READ_SAMPLE_INTERPOLATED;
		}
	}
	else {
		return PTC_READ_SAMPLE_INVALID;
	}
}

} /* namespace PTC */