Example 2 : Multi Sampling And Filtering Methods

#include<vector>
#include<iostream>
#include"Vector3.h"
#include"rgb.h"
#include"Image.h"
#include"Shape.h"
#include"Triangle.h"
#include"Sphere.h"
#include <fstream>
#include "Sample.h"
using namespace std;


#define IMAGE_WIDTH		512
#define IMAGE_HEIGHT	384
#define NUM_SAMPLES		16

int main()
{

	Image im(IMAGE_WIDTH, IMAGE_HEIGHT);

	int sample_type, r, c, s;

	Vector2* xySamples = new Vector2[NUM_SAMPLES];

	float x, y, total, tmp;

	ofstream singleFile("single.ppm");
	ofstream box_16File("box_16.ppm");
	
	Sample sampler;

	for (sample_type = 0; sample_type < 4; sample_type++)
	{
		
		for (r = 0; r < IMAGE_HEIGHT; r++)
		{
			for (c = 0; c < IMAGE_WIDTH; c++)
			{
				switch (sample_type)
				{
				case 0:
					for (s = 0; s < NUM_SAMPLES; s++)
					{
						xySamples[s].setX(0);
						xySamples[s].setY(0);
					}
					break;
				case 1:
					// jitter 理解为: 为一个pixel, 产生NUM_SAMPLES个偏移值
					sampler.jitter(xySamples, NUM_SAMPLES);
					//sampler.multiJitter()

					// filter 理解为: 控制一个pixel,NUM_SAMPLES个偏移值的范围,从[0,1] -> [-0.5, 0.5]
					sampler.boxFilter(xySamples, NUM_SAMPLES);
					//sampler.cubicFilter()
					break;

				}	
				// this is a 2D function defined  for sample locations in screen space,so it is evaluated directly instead of tracing rays. 
				total = 0;
				for (s = 0; s < NUM_SAMPLES; s++)
				{
					x = c + xySamples[s].x();
					y = r + xySamples[s].y();
					tmp = (x*x + y*y) / 100;
					total += 0.5f * (1.0f + (float)sin(tmp));
				}
				// 平均一个Pixel的颜色
				total /= NUM_SAMPLES;

				im.set(r, c, rgb(total, total, total));
				
			}
		}

		if (sample_type == 0){
			im.writePPM(singleFile);
		}
		else{
			im.writePPM(box_16File);
		}
	}
}




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
This accessible book provides an introduction to the analysis and design of dynamic multiagent networks. Such networks are of great interest in a wide range of areas in science and engineering, including: mobile sensor networks, distributed robotics such as formation flying and swarming, quantum networks, networked economics, biological synchronization, and social networks. Focusing on graph theoretic methods for the analysis and synthesis of dynamic multiagent networks, the book presents a powerful new formalism and set of tools for networked systems. The book's three sections look at foundations, multiagent networks, and networks as systems. The authors give an overview of important ideas from graph theory, followed by a detailed account of the agreement protocol and its various extensions, including the behavior of the protocol over undirected, directed, switching, and random networks. They cover topics such as formation control, coverage, distributed estimation, social networks, and games over networks. And they explore intriguing aspects of viewing networks as systems, by making these networks amenable to control-theoretic analysis and automatic synthesis, by monitoring their dynamic evolution, and by examining higher-order interaction models in terms of simplicial complexes and their applications. The book will interest graduate students working in systems and control, as well as in computer science and robotics. It will be a standard reference for researchers seeking a self-contained account of system-theoretic aspects of multiagent networks and their wide-ranging applications. This book has been adopted as a textbook at the following universities: University of Stuttgart, Germany Royal Institute of Technology, Sweden Georgia Tech, USA University of Washington, USA Ohio University, USA
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值